• 0

JavaScript Array Match


Question

I'm creating a toolbar for my soon coming redesigned site Illing Spree and I want to make sure only the sites listed in the array "ill_members" will only load the bar, that way there's such things as an authorization. But I'm not exactly sure how to make these if statements. Can anyone help? :)

Also: This is all being written inside a JavaScript file, hence making a bootstrap so the other sites wouldn't go through the trouble of installing or working with upgrades.



var jQueryScriptOutputted=false;function initJQuery(){if(typeof jQuery=="undefined"){if(!jQueryScriptOutputted){jQueryScriptOutputted=true;document.write("<scr"+"ipt type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></scr"+"ipt>")}}else $(function(){})}initJQuery();

var ill_members = [
	{name: "Illing Spree", link: "illingspree.com"},
	{name: "WeAreRap.com", link: "wearerap.com"},
{name: "Gossip On Time", link: "gossipontime.com"}
];

var ill_music_members = [
	{name: "WeAreRap.com", link: "wearerap.com"},
];

var dyno = "http://dyno.illingspree.com/toolbar/v0.1/";
var illBar = "<div id='illbar'><a id='illbar-logo' href='http://illingspree.com'></a></div>";

$(document).ready(function () {
$('head').append("<link rel='stylesheet' type='text/css' href='" + dyno + "tb.css'/>");
$('body').append(illBar);
});

Link to comment
https://www.neowin.net/forum/topic/1110673-javascript-array-match/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Following checks if certain text is part of the url, this won't make a difference between .com, .org, .net, etc.

JS:

if(document.location.href.search(illingspree) != -1)
/*load bar*/
else if(document.location.href.search(wearerap) != -1)
/*load bar*/
else if(document.location.href.search(gossipontime) != -1)
/*load bar*/
else
/*do nonting*/[/CODE]

  • 0

Something along these lines should do it.

Ignore the wacky indenting, Neowin's text editor screws it up and I'm on a laptop so can't be bothered fixing it :p

function load_bar ()
{
  var dyno = "http://dyno.illingspree.com/toolbar/v0.1/",
	  illBar = "<div id='illbar'><a id='illbar-logo' href='http://illingspree.com'></a></div>";

  $('head').append("<link rel='stylesheet' type='text/css' href='" + dyno + "tb.css'/>");
  $('body').append(illBar);
}

$(document).ready(function ()
{
  var current_domain = location.href.substr( location.protocol.length + 2 ).split('/')[0].replace(/^www\./i, '').toLowerCase(),
	  i = 0,
	  ill_members_length = ill_members.length;

  for (i; i < ill_members_length; i++)
  {
	if (ill_members[i].link.toLowerCase() === current_domain)
	{
	  load_bar();
	  break;
	}
  }
});

  • 0

Ahh JoeC, your sample was perfect to work with! :D It's a huge step for me.

Here's what I have down. :) I can now tell others that they can't use the bar if they're not listed on the network.


var ill_members = [
    {name: "Illing Spree", link: "illingspree.com"},
    {name: "WeAreRap.com", link: "wearerap.com"},
{name: "Gossip On Time", link: "gossipontime.com"}
];


  var dyno = "http://dyno.illingspree.com/toolbar/v0.1/",
          illBar = "<div id='illbar'><a id='illbar-logo' href='http://illingspree.com'></a></div>";

  $('head').append("<link rel='stylesheet' type='text/css' href='" + dyno + "tb.css'/>");
  $('body').append(illBar);


function load_bar ()
{
var dyno = "http://dyno.illingspree.com/toolbar/v0.1/";
var illBar = ("<div id='illbar'><a id='illbar-logo' href='http://illingspree.com'></a><div id='illbar-feed'></div></div>");
$(document).ready(function () {
$('head').append("<link rel='stylesheet' type='text/css' href='" + dyno + "tb.css'/>");
$('body').append(illBar);
$('#illbar-feed').rssfeed('http://illingspree.com/feed',{
header: true,
titletag: 'div',
date: false,
content: false,
limit: 5
}, function(e) {
$.zazar.rotate({selector: '#illbar-feed ul'});
});
});
}

$(document).ready(function () {
  var current_domain = location.href.substr( location.protocol.length + 2 ).split('/')[0].replace(/^www\./i, '').toLowerCase(),
          i = 0,
          ill_members_length = ill_members.length;

  for (i; i < ill_members_length; i++)
  {
        if (ill_members[i].link.toLowerCase() === current_domain)
        {
          load_bar();
          break;
        } else {
$('body').prepend("<p>Disclaimer: This site is not a part of the Illing Spree network. Please remove this script.</p>");
break;
}
  }
});

  • 0

One slight change - instead of making that else put your disclaimer in (because you'll find it fires 2 times on valid sites, and 3 times on invalid sites), you'll need to add a "valid domain" flag -

function invalid_site ()
{
  $('body').prepend("<p>Disclaimer: This site is not a part of the Illing Spree network. Please remove this script.</p>");
}

$(document).ready(function ()
{
  var current_domain = location.href.substr( location.protocol.length + 2 ).split('/')[0].replace(/^www\./i, '').toLowerCase(),
    i = 0,
    ill_members_length = ill_members.length,
    valid_site = false;

  for (i; i < ill_members_length; i++)
  {
    if (ill_members[i].link.toLowerCase() === current_domain)
    {
      valid_site = true;
      load_bar();
      break;
    }
  }

  ! valid_site && invalid_site();
}

  • 0

I noticed that, I thought using the break for the else statement would help. That works perfectly, broski, thanks!

There's just one more thing. Besides appending the CSS file in the head, I tried doing the same for these files (the ones that load the RSS feed), but instead, prepend the toolbar file since it's jQuery and a function can't be placed before a library. I even gave the <script> an ID but it never helped. I'm basically trying to load all the files in order.


&lt;script src='http://www.zazar.net/developers/jquery/zrssfeed/jquery.zrssfeed.min.js' type='text/javascript'&gt;&lt;/script&gt;
&lt;script src="https://admin.zazar.net/__system/_js/zframework/jquery.zframework.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script id="ill-toolbar" type="text/javascript" src="https://dyno.illingspree.com/toolbar/v0.1/illbar.js"&gt;&lt;/script&gt;

  • 0

EDIT: Nevermind, I got it! Sorry!

I don't think I'm doing it right as far as the domain matching, because all of them load the same bar instead of making Sexes Battle a chicks bar itself.

link


$(document).ready(function () {
var ill_members = [
{name: "Illing Spree", link: "illingspree.com"}
],

ill_chicks_members = [
{name: "Sexes Battle", link: "sexesbattle.com"}
],

ill_music_members = [
{name: "WeAreRap.com", link: "wearerap.com"}
],

ill_pop_culture_members = [
{name: "Gossip On Time", link: "gossipontime.com"}
],

ill_author_members = [
{name: "Mr.XXIV", link: "mrxxiv.com"}
];

	var current_domain = location.href.substr(location.protocol.length + 2).split('/')[0].replace(/^www\./i, '').toLowerCase(),
		i = 0,
		ill_members_length = ill_members.length,
		valid_site = false;

	for (i; i &lt; ill_members_length; i++) {
		if (ill_members[i].link.toLowerCase() === current_domain) {
			valid_site = true;
			load_bar('');
			break;
		} else if (ill_music_members[i].link.toLowerCase() === current_domain) {
			valid_site = true;
			load_bar('-music');
			break;
		} else if (ill_pop_culture_members[i].link.toLowerCase() === current_domain) {
			valid_site = true;
			load_bar('-pop-culture');
			break;
		} else if (ill_author_members[i].link.toLowerCase() === current_domain) {
			valid_site = true;
			load_bar('-author');
			break;
		} else if (ill_chicks_members[i].link.toLowerCase() === current_domain) {
			valid_site = true;
			load_bar('-chicks');
			break;
		}
	}!valid_site &amp;&amp; invalid_site();
});
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Apple is expanding Private Cloud Compute beyond its own data centers by Pradeep Viswanathan At WWDC 2026, as part of the improved Apple Intelligence capabilities, Apple today announced that it is expanding Private Cloud Compute (PCC), its privacy-focused cloud infrastructure for Apple Intelligence, beyond its own data centers for the first time. Private Cloud Compute was designed to handle Apple Intelligence requests that are too complex to run fully on-device. The PCC system does not store user data and does not allow Apple or anyone else to access user requests. Last year, Apple also expanded its Security Bounty program with rewards of up to $1 million for researchers who could find serious vulnerabilities in PCC. Until now, Apple's PCC data centers were using Apple's own silicon. As part of the expansion, Apple is working with Google and NVIDIA to run new Apple Intelligence workloads on Google Cloud systems powered by NVIDIA GPUs. Apple will be using this new infrastructure to execute more demanding AI tasks while maintaining the same privacy and security guarantees of PCC. The new implementation uses NVIDIA Confidential Computing with NVIDIA GPUs, Intel CPUs with TDX, and Google’s Titan chip. Apple says it has worked with Google to build additional protections beyond a traditional confidential computing deployment. Despite the expansion to third-party data centers, Apple claims that its core PCC requirements remain unchanged, including stateless computation, no privileged runtime access, non-targetability, and verifiable transparency. The company highlighted that it will continue to control the PCC software stack, and Apple devices will only trust PCC software that has been cryptographically approved by Apple. To take security to the next level, Apple mentioned that it is maintaining an append-only ledger of Google Cloud hardware that is part of the PCC fleet. The company claims this will help reduce the risk of supply chain attacks. In addition to AI infrastructure, Apple also worked with Google to use technologies behind the Gemini family of models to build the next generation of Apple Foundation Models to power Apple Intelligence features across on-device and cloud workloads. As expected, for more demanding AI tasks like agentic tool use and complex reasoning, Apple will rely on the expanded PCC infrastructure running on Google Cloud. The expansion of PCC on Google Cloud will gradually ramp toward the full set of protections during the summer preview period. As before, Apple will also publish binaries for public inspection, provide research tooling, and give researchers access to live PCC nodes in research mode through the Apple Security Bounty Program.
    • my problem with outlook (new) is that it connects only to outlook.com. all connections to external providers goes through there. Got your mail server and want to use imap directly? no way... it adds a connector on outlook.com. last bug; if your email on an external provider if the same as principal email of your microsoft account, it doesn't work...
    • It's the only reason I finally have an iPhone (for work) and enjoy using it so much that I'm tempted to move from android next time I need to replace my own device
    • So is Russia, China, Iran, North Korea, just to mention a few. What's your point? Everyone is a threat from their enemies' perspective. I'd say that Israel is only a threat to their immediate enemies like Hamas, Hezbollah and the Iranian regime, not to anyone else.
    • The government is not the good guy either. You propose 99% of people require that the government overreach and govern their freedom of information and privacy, while ignoring the government is made up 100% of people, of which 99% are (as you described) brain dead. You can't have both. The reality is Signal is absolutely right and the government is doing what it has always done. Ignoring that we are their boss and grabbing all the power they possibly can to make sure we aren't. Your (societies) ###### parenting is not reason enough as to why I can't have a safe platform for my data/information. Thinking the government is helping is precisely what they are targeting psychologically to take suckers like you for a ride. "Think of the children" was, has, is, and will always be a mechanism of control. In the rare occasion it's actually essential the mass consensus has always been there and it doesn't become a debate.
  • Recent Achievements

    • Very Popular
      Captain_Eric earned a badge
      Very Popular
    • One Month Later
      amusc earned a badge
      One Month Later
    • One Month Later
      DJC50PLUS earned a badge
      One Month Later
    • Week One Done
      DJC50PLUS earned a badge
      Week One Done
    • Proficient
      Eric Biran went up a rank
      Proficient
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      PsYcHoKiLLa
      222
    3. 3
      ATLien_0
      92
    4. 4
      +Edouard
      86
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!