Google result tweaker

Mark & re order spam sites

2018-12-23 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Google result tweaker
// @namespace    https://www.topcl.net/
// @version      0.2
// @description  Mark & re order spam sites
// @author       VJ
// @match        https://www.google.com/search?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const resultSections=document.querySelectorAll('#rso > div > div.srg');
    if(0==resultSections.length){ console.warn("No result found, google has page layout update?"); return; }
    const lastResultSection = resultSections[resultSections.length-1];

    const BlockList=[
        {hostname:"blog.csdn.net",reason:"低质量社区",tobottom:true},
        {hostname:"bbs.csdn.net",reason:"低质量社区",tobottom:true},

        {hostname:"www.logphp.com",reason:"链接站",tobottom:true},

        {hostname:"www.voidcn.com",reason:"采集",tobottom:true},
        {hostname:"tw.saowen.com",reason:"采集",tobottom:true},
        {hostname:"stackoverrun.com",reason:"机翻采集",tobottom:true},
        {hostname:"codeday.me",reason:"机翻采集",tobottom:true},
    ];

    const BlockHandler=(result,config)=>{
        result.style.opacity='.5';
        const cite = result.querySelector('cite');
        cite.innerText=`[${config.reason}] ${cite.innerText}`;
        if(config.tobottom){ lastResultSection.appendChild(result); }
    };

    const handledEntries=[];

    for(let c=0; c<resultSections.length; c++)
    {
        const resultContainer = resultSections[c];
        var items = resultContainer.querySelectorAll('div.g');
        for(let i=0;i<items.length;i++)
        {
            const resultEntry = items[i];
            if(-1!=handledEntries.indexOf(resultEntry)) continue;

            const link = resultEntry.querySelector('div.r a');
            const cite = link.querySelector('cite');
            const hostname = link.hostname;

            for(let j=0;j<BlockList.length;j++){
                const confEntry=BlockList[j];
                if(hostname==confEntry.hostname){
                    BlockHandler(resultEntry,confEntry);
                    handledEntries.push(resultEntry);
                    --i;
                    break;
                }
            }

        }
    }
})();