DLE links decoder

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

Stan na 18-08-2016. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
})();