DLE links decoder

Прямые ссылки на сайтах с движком DataLife Engine (DLE)

Verze ze dne 18. 08. 2016. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         DLE links decoder
// @namespace    lainscripts_dle_links_decoder
// @version      0.1
// @description  Прямые ссылки на сайтах с движком DataLife Engine (DLE)
// @author       lainverse
// @match        *://*/*
// @grant        none
// ==/UserScript==
// Script based on a similar script by raletag:
// https://greasyfork.org/en/scripts/22290-%D0%9F%D1%80%D1%8F%D0%BC%D1%8B%D0%B5-%D1%81%D1%81%D1%8B%D0%BB%D0%BA%D0%B8-%D0%B2-dle/code

(function() {
    'use strict';

    var win = window;

    function isBase64(str) {
        try {
            return win.btoa(win.atob(str)) == str;
        } catch (err) {
            return false;
        }
    }

    function clickHandler(e){
        var link = e.target, url = link.href, url64;
        if (!url) {
            return true;
        }
        url64 = decodeURIComponent((url.match(/[?&]url=([^&]*)(&|$)/i)||[])[1]);
        if (!url64) {
            return true;
        }
        if (isBase64(url64)) {
            url = win.atob(url64);
            console.log('Replaced ' + link.href + ' with ' + url);
            e.target.href = url;
        }
        return true;
    }

    document.addEventListener('click', clickHandler, false);
    document.addEventListener('contextmenu', clickHandler, false);
})();