Created
August 24, 2014 13:48
-
-
Save yumauri/bd5d6334a783a76eafb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name neagent.by hide ads | |
// @description Hide uninteresting ads from view | |
// @author [email protected] | |
// @include http://neagent.by/* | |
// ==/UserScript== | |
/* jshint browser: true, jquery: true, -W099, smarttabs: true, undef: true, unused: true, bitwise: true, curly: true, quotmark: single, trailing: true */ | |
(function() { | |
'use strict'; | |
if (window.location.hostname != 'neagent.by') { | |
return; | |
} | |
// name of local storage key | |
var storageKey = 'yu_hidden_ads'; | |
// get hidden ads from local storage, as object | |
function getHidden() { | |
var stored = localStorage.getItem(storageKey), | |
hidden; | |
try { | |
if (stored) { | |
hidden = JSON.parse(stored); | |
} | |
} catch(e) {} | |
if (!hidden) { | |
hidden = {}; | |
} | |
return hidden; | |
} | |
// save hidden ads to local storage | |
function setHidden(hidden) { | |
localStorage.setItem(storageKey, JSON.stringify(hidden)); | |
} | |
// hide ad and save it ID to local storage | |
function hideAd(e) { | |
var $el = $(e.currentTarget).parents('.itm'), | |
id = $el.attr('id'); | |
$el.hide(); | |
var hidden = getHidden(); | |
hidden[id] = 1; | |
setHidden(hidden); | |
} | |
// hide all already hidden ads | |
var hidden = getHidden(), | |
id, | |
hiddenCount = 0, | |
hiddenOnPageCount = 0; | |
for (id in hidden) { | |
var $ad = $('#' + id); | |
hiddenCount++; | |
if ($ad.length !== 0) { | |
hiddenOnPageCount++; | |
$ad.hide(); | |
} | |
} | |
// add crosses | |
$('.itm table.itm_head td:last-child').each(function() { | |
var $cross = $( | |
'<div style="float:right;font-size:2em;font-weight:bold;color:red;cursor:pointer;">×</div>' | |
).click(hideAd); | |
$(this).prepend($cross); | |
}); | |
// add 'show all' button | |
var $check = $( | |
'<span style="margin-left:20px;color:green;cursor:pointer;">' + | |
'<span style="vertical-align:middle;font-size:2em;font-weight:bold;">✔</span>' + | |
'show all (' + hiddenCount + ' hidden ads total, ' + hiddenOnPageCount + ' on this page)' + | |
'</span>' | |
).click(function() { | |
setHidden(null); | |
location.reload(); | |
}); | |
$('.orderoptions').append($check); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment