CFake.com image and link fixer

Enables middle click to open new tab, hides ads, and automatically loads the high res image

Versione datata 23/04/2021. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        CFake.com image and link fixer
// @namespace   cfake.com/*
// @version      1.0
// @description  Enables middle click to open new tab, hides ads, and automatically loads the high res image
// @author       codingjoe
// @match        https://cfake.com/*
// @grant        none
// ==/UserScript==

// cut the bs
document.body.onload = function () {};
document.body.style.overflow = "auto";

// xpath
function $x(xpath, root) {
    let doc = root ? root.evaluate ? root : root.ownerDocument : document, next;
    let got = doc.evaluate(xpath, root || doc, null, null, null), result = [];
    while (next = got.iterateNext()) result.push(next);
    return result;
}

(function() {
    'use strict';
    var strMatch = "javascript:showimage('";
    
    // hide ads
    $x("//*[contains(@class, 'footer_style')] | //*[contains(@class, 'display_a_right')]").forEach(ad => {
        ad.style.display = "none";
    });
    
    // enables middle click to open page in new tab
    $x(`//a[contains(@href, "${strMatch}")]`).forEach(link => {
        var pos = link.href.indexOf(".jpg")+4;
        link.href = link.href.substring(strMatch.length, pos);
    })

    // retrieve high res image
    $x("//img[contains(@src, 'medias/photos')]").forEach(img => {
        let txt = $x("//script[text()[contains(., 'path_original')]]")[0].innerHTML;
        let pic = /mypicture\s*=\s*'([^']+)';/.exec(txt)[1];
        let path = /path_original\s*=\s*'([^']+)';/.exec(txt)[1];

        let fulllink = `https://cfake.com/${path}${pic}`;
        img.src = fulllink;
        img.parentNode.href = fulllink;
    });
})();