Skip to content

Instantly share code, notes, and snippets.

@snaka
Created July 18, 2009 08:21

Revisions

  1. snaka revised this gist Jul 25, 2009. 1 changed file with 48 additions and 29 deletions.
    77 changes: 48 additions & 29 deletions jaro.user.js
    Original file line number Diff line number Diff line change
    @@ -8,40 +8,32 @@
    // @license MIT license (http://www.opensource.org/licenses/mit-license.php)
    // ==/UserScript==
    (function() {
    const DATABASE = 'http://wedata.net/databases/SPAM_Sites';
    const STORE_KEY = 'jaroCacheInofo';
    const CACHE_EXPIRE = 1000 * 60 * 60 * 24;
    var sites = [];
    var local_setting = [
    /*
    (example)
    var localSetting = [
    /* (example)
    '^http:\/\/\w+\.designlinkdatabase\.net',
    '^http:\/\/\w+\.thumbnailcloud\.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/
    */
    /* (example)
    /^http:\/\/\w+\.designlinkdatabase\.net/ */
    ];

    GM_registerMenuCommand('jaro - clear cache', clearCache);

    if (window.AutoPagerize) {
    window.AutoPagerize.addDocumentFilter(function(doc) {
    setOpacity(sites, doc);
    });
    }

    //
    // main logic
    //
    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',
    url: DATABASE + '/items.json',
    onload: function(res) {
    try {
    sites = [i.data.url_pattern for each(i in eval(res.responseText))];
    @@ -52,16 +44,9 @@
    });
    }

    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) {
    if (!cacheInfo || cacheInfo.expire < new Date) {
    return null;
    }
    return cacheInfo.sites;
    @@ -76,12 +61,13 @@
    }

    function setOpacity(sites, doc) {
    mergedSites = sites.concat(local_setting);
    mergedSites = sites.concat(localSetting);
    $X('//a[@class="l"]', doc).forEach(function(ele) {
    if (isExcepts(ele.href)) {
    var link = ele.href;
    if (isExcepts(link)) {
    return;
    }
    if (isTarget(ele.href, mergedSites)) {
    if (isTarget(link, mergedSites)) {
    ele.parentNode.parentNode.style.opacity = '0.3';
    }
    });
    @@ -95,4 +81,37 @@
    return sites.some(function(i) { return url.match(i) });
    }

    //
    // Register menu command
    //
    GM_registerMenuCommand('jaro - clear cache', clearCache);

    function clearCache() {
    GM_setValue(STORE_KEY, 'null');
    alert("Cache cleared.");
    }

    GM_registerMenuCommand('jaro - go to Wedata', gotoWedata);

    function gotoWedata() {
    window.open(DATABASE + '/items');
    }

    //
    // Register page handler
    //
    if (window.AutoPagerize) {
    registerPageHandler();
    } else {
    window.addEventListener('GM_AutoPagerizeLoaded', registerPageHandler, false);
    }

    function registerPageHandler() {
    window.AutoPagerize.addFilter(function(pages) {
    pages.forEach(function(page) {
    setOpacity(sites, page);
    });
    });
    }

    })();
  2. snaka revised this gist Jul 22, 2009. 1 changed file with 85 additions and 8 deletions.
    93 changes: 85 additions & 8 deletions jaro.user.js
    Original file line number Diff line number Diff line change
    @@ -4,18 +4,95 @@
    // @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 sites = [
    /^https?:\/\/\w+\.designlinkdatabase\.net/,
    /^https?:\/\/\w+\.thumbnailcloud\.net/,
    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);
    });
    }

    $X('/html/body/div[4]/div/ol/li/h3/a').forEach(function(ele){
    sites.forEach(function(site) {
    if (ele.href.match(site))
    ele.parentNode.parentNode.style.opacity = '0.3'
    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) });
    }

    })();
  3. snaka revised this gist Jul 19, 2009. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions jaro.user.js
    Original file line number Diff line number Diff line change
    @@ -8,15 +8,13 @@
    (function() {
    const sites = [
    /^https?:\/\/\w+\.designlinkdatabase\.net/,
    /^https?:\/\/\w+\.thumbnailcloud\.net/,
    ];

    $X('/html/body/div[4]/div/ol/li/h3/a').forEach(function(ele){
    sites.forEach(function(site) {
    if (ele.href.match(site)) {
    [ele.parentNode, ele.parentNode.parentNode].forEach(function(ele){ with(ele){
    style.opacity = '0.3'
    }});
    }
    if (ele.href.match(site))
    ele.parentNode.parentNode.style.opacity = '0.3'
    });
    });

  4. snaka revised this gist Jul 18, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jaro.user.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    // ==/UserScript==
    (function() {
    const sites = [
    /^https?:¥/¥/¥w+¥.designlinkdatabase¥.net/,
    /^https?:\/\/\w+\.designlinkdatabase\.net/,
    ];

    $X('/html/body/div[4]/div/ol/li/h3/a').forEach(function(ele){
  5. snaka created this gist Jul 18, 2009.
    23 changes: 23 additions & 0 deletions jaro.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // ==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/*
    // ==/UserScript==
    (function() {
    const sites = [
    /^https?:¥/¥/¥w+¥.designlinkdatabase¥.net/,
    ];

    $X('/html/body/div[4]/div/ol/li/h3/a').forEach(function(ele){
    sites.forEach(function(site) {
    if (ele.href.match(site)) {
    [ele.parentNode, ele.parentNode.parentNode].forEach(function(ele){ with(ele){
    style.opacity = '0.3'
    }});
    }
    });
    });

    })();