KodeItDEV / JiffProxy

// ==UserScript==
// @name         JiffProxy
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Web proxy using Google Translate
// @author       KodeItDEV
// @icon         https://www.graphicsprings.com/filestorage/stencils/020f9e41b7a57c69fbbd8d2c74731c1b.svg
// @licence      MIT
// @include      *
// @exclude      *.googleusercontent.com
// @exclude      notifications.*
// @require      https://raw.githubusercontent.com/eight04/GM_config/master/dist/GM_config.js
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @grant        GM_openInTab
// ==/UserScript==

GM_registerMenuCommand('[Proxy Settings]', settings);

GM_config.init( 'Proxy Settings', {
    select: {
        label: "Should JiffProxy be used on all sites?",
        type: "radio",
        default: "no",
        options: {
            no: "No (Default)",
            yes: "Yes"
        }
    },
    sites: {
        label: "If no, please specify what sites you want to use JiffProxy on:",
        type: "textarea",
        default: "www.google.com"
    }
});

var sites = GM_getValue('jiffproxsites');
for (var y in sites) {
    (function () {
        var url = window.location.host + window.location.pathname;
        var proxurl = 'https://translate.google.com/translate?sl=es&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u='+url+'&sandbox=1';
        if (window.location.host === sites[y]) {
            if (window.location.host === 'translate.google.com') {
                window.onload = setTimeout(function () {
                    var x = document.getElementsByTagName("iframe")[0];
                    x.setAttribute("id", "framecontent");
                    proxurl = document.getElementById("framecontent").src;
                    window.location.replace(proxurl);
                }, 1000)();
            } else {
                window.location.replace(proxurl);
            }
        }
    }());
}

GM_config.onclose = (function(saveFlag) {
    if (saveFlag) {
        if (GM_config.get('select') === 'no') {
            var proxsites = GM_config.get('sites').split('\n');
            GM_setValue('jiffproxsites', proxsites);
        }
    }
});

function settings() {
    GM_config.open();
}