Created
July 18, 2009 08:21
-
-
Save snaka/149474 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 jaro | |
// @namespace http://d.hatena.ne.jp/snaka72/ | |
// @require http://gist.github.com/raw/3242/9dc0cdee5e975d275c7ab71f581d272eb316674f/dollarX.js | |
// @include http://www.google.com/* | |
// @include http://www.google.co.jp/* | |
// @author [email protected] | |
// @license MIT license (http://www.opensource.org/licenses/mit-license.php) | |
// ==/UserScript== | |
(function() { | |
const STORE_KEY = 'jaroCacheInofo'; | |
const CACHE_EXPIRE = 1000 * 60 * 60 * 24; | |
var sites = []; | |
var local_setting = [ | |
/* | |
(example) | |
'^http:\/\/\w+\.designlinkdatabase\.net', | |
'^http:\/\/\w+\.thumbnailcloud\.net', | |
*/ | |
]; | |
// If you want to negate the filter, set the pattern of the site names here. | |
var antiFilter = [ | |
/* | |
(example) | |
/^http:\/\/\w+\.designlinkdatabase\.net/ | |
*/ | |
]; | |
GM_registerMenuCommand('jaro - clear cache', clearCache); | |
if (window.AutoPagerize) { | |
window.AutoPagerize.addDocumentFilter(function(doc) { | |
setOpacity(sites, doc); | |
}); | |
} | |
if (sites = getCache()) { | |
GM_log("USE CACHE"); | |
setOpacity(sites); | |
} else { | |
GM_log("REQUEST TO REMOTE"); | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: 'http://wedata.net/databases/SPAM_Sites/items.json', | |
onload: function(res) { | |
try { | |
sites = [i.data.url_pattern for each(i in eval(res.responseText))]; | |
setOpacity(sites); | |
storeCache(sites); | |
} catch(e) { } | |
} | |
}); | |
} | |
function clearCache() { | |
GM_setValue(STORE_KEY, 'null'); | |
} | |
function getCache() { | |
var cacheInfo = eval(GM_getValue(STORE_KEY)); | |
if (!cacheInfo) { | |
return null; | |
} | |
if (cacheInfo.expire < new Date) { | |
return null; | |
} | |
return cacheInfo.sites; | |
} | |
function storeCache(sites) { | |
var cacheInfo = { | |
expire: new Date((new Date()).getTime() + CACHE_EXPIRE), | |
sites: sites | |
}; | |
GM_setValue(STORE_KEY, cacheInfo.toSource()); | |
} | |
function setOpacity(sites, doc) { | |
mergedSites = sites.concat(local_setting); | |
$X('//a[@class="l"]', doc).forEach(function(ele) { | |
if (isExcepts(ele.href)) { | |
return; | |
} | |
if (isTarget(ele.href, mergedSites)) { | |
ele.parentNode.parentNode.style.opacity = '0.3'; | |
} | |
}); | |
} | |
function isExcepts(url) { | |
return antiFilter.some(function(i) { return url.match(i) }); | |
} | |
function isTarget(url, sites) { | |
return sites.some(function(i) { return url.match(i) }); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment