• 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

    • I'm reading the reports as EU rejecting Apple's proposal because Trusted System Agent would be an intermediary offered to third party AI's (this article is also worded as such) but Siri AI itself would not pass this intermediary. This would cause a situation where Siri AI would have more direct system access and offer it an unfair advantage. (speaking from EU regulator perspective here) Apple is citing security issues with doing what EU asked for, and I think this also supports this theory, because truly direct system access like Siri AI would make it impossible to control third party AI's running on the devices and e.g. reign them in via adjustments to Trusted System Agent. So, I _think_ this is the sticking point right now: EU saying they need to be on equal footing as Siri AI, Apple saying they can't be because Apple only trusts their own AI. Apple could of course be leaning a bit extra hard towards this because they're biased. One method to find an agreement would be to have Siri AI also run through Trusted System Agent and treat it as untrusted. This kind of defensive architecture design (especially when involving an AI) would honestly not be a very bad idea from a sheer engineering standpoint. But then Apple would need to swallow their pride and adapt worldwide due to EU, and make perhaps major updates delaying Siri AI once more.
    • I have not even heard of that game. will take a look
    • Chasys Photo 5.41.01 by Razvan Serea Chasys Photo is a suite of image editing applications including a layer-based image editor with adjustment layers, linked layers, timeline and frame-based animation, icon editing, image stacking and comprehensive plug-in support (Chasys Photo Editor), a fast image viewer (Chasys Photo Viewer) and a fast multi-threaded image file converter (Chasys Photo Converter) , with RAW image support in all components. It supports the native file formats of several competitors including Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr, and the whole suite is designed to make effective use of multi-core processors, touch-screens and pen-input devices. Designed under the mantra of “unique, flexible and powerful”, Chasys Photo takes a radically different approach to image editing with the aim of opening up new possibilities for those who dare to be different. Chasys Photo key features: Free-style layering with blending modes Adjustment layers with multiple adjustments per layer Linked layers (a.k.a Linked Smart Objects) Composite, Image List, Frame Animation and Object Animation image modes Animation, both frame-based and object-based (timeline animation) Animation Composer engine Image Stacking for noise reduction, super-resolution, etc. Tablet/Pen-input/Stylus support with pressure control Touch-screen support with gestures including pitch-to-zoom and multi-finger panning Support for the native formats of Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr Support for common formats such as JPEG, animated PNG, animated GIF, TIFF, PICT, WebP, HEIF, DDS, JPEG-2000, JPEG-XR, JPEG-XL, AVI video, etc. Support for the OpenRaster interchange file format and rare formats such as QOI, MNG/JNG and DPX Support for older formats such as PPM/PGM/PBM, PCX/DCX, PCD, TGA, COKE, etc. Comprehensive Camera RAW file support with live adjustment Extensive plug-in support with streamlined SDKs Support for Photoshop Filter Plug-ins (.8BF) Advanced printing and scanning engines PDF document generation Icon and cursor editing, import and export, including Vista-style and Mac-OS icons Screen Capture, including Video Screen Capture with multiple triggering modes Video capture from devices (e.g. TV/Video) Supports multi-core processors, High-DPI displays and Multiple Display setups Integrated File Browser, Bluetooth OBEX and in-built utilities (Calculator, Notepad) Shell integration with thumbnails and conflict detection Unlimited Undo/Redo and Asynchronous Auto-Save, with Just-in-time memory compression to save space Fully re-editable text with advanced styling and effects (TextArt) Full alpha channel through out the workflow with Alpha protection (a.k.a. transparency protection) Multiple language support with user-editable language files and translation assistant (Chasys Photo Language Studio) Anti-aliasing and super-sampling support in tools and paths* Smart-resizing (similar to seam-carving) Best-in-class post-edit heuristics anti-aliasing engine Physical measurement specification with display size detection via EDID Uses the latest CD5 specification with animation and multi-resolution Super-fast internal graphics engine (JpDRAW2) Full UNICODE support in all components Metadata save, restore and scale to imitate vector art Configurable Guides and Grids with Snap-to-Grid Smart-dither to custom palette Asynchronous preview rendering engine Pantone equivalent palettes for PMS 100 to 814-2x Automatic color naming ... and many more! Chasys Photo 5.41.01 changelog: New Features Layered images with multiple pages (Composite/Multi-page) Additional templates to support template-centric workflow New Layer Blend Mode: Inverse Luma Mask Horizon detection in Rotate Transform Cropping option when importing video Orientation options in QR Code Generator plug-in Solved angle ambiguities (CCW versus CW) Internal Improvements Improved graphics engine (JpDRAW2™ v26.05) Improved CD5 codec (v4.10, improved ACSC compression) Improved interpolation when downsizing images Improved motion detection in Video Capture Slightly lower memory usage (RAM is getting expensive!) File Support and Bug Fixes Improved PXZ file support (placeholders, blanks) [bug-fix] Memory leak in flt_JPEG.dll Download: Chasys Photo 5.41.01 | 46.1 MB (Freeware) View: Chasys Photo Home Page | Wikipedia Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • We don't need stars for the word, just use the word "CSAM"
  • 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
      220
    3. 3
      ATLien_0
      92
    4. 4
      +Edouard
      90
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!