rdvdnl / Leo's Popup Generator

// ==UserScript==
// @name         Leo's Popup Generator
// @author       Leo Takacs // Scam Baiting
// @version      1.3
// @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @match        *www.popup.com*
// @match        *www.popup.com/finder*
// @grant        unsafeWindow
// ==/UserScript==
var vers = 1.3;
var defaultIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAB3RJTUUH4gQEDzc6sO0fBQAAAAZiS0dEAAAAAAAA+UO7fwAACwJJREFUeNrtXXtMVfcd543ARbg8VFCwAhfwwUMFK68iBVTkJWy1rmW1VaTo4tJGZ9JNhS1Z02zLLKXpurm5/TPbZZnJtm6JWRYjwcwggo3ZHzJtZ9ut902zpOve332/5x6QWu7h6Dnnd+85fL/JJ8SYnHPP+Zzv9/N9/H7nRESwsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsZndohHJiOWIlYjcECAHkY1IR8QjIpkWbYTSDW1DnEL8DDGK+CPiFuJOCPAu4iZiAnEB8T1EP6ISsZQpU2fkpS2IM/LN/AcCwhj/Q/gQI4jjiGJEFNP4WUtEdMue8XGYk6pENnn6t2SiOYTLVoY4Z2Ji58OfEEcWe+iORfTImgoWxL/k3KFwMZKbhDiJ+JtFyZ2LcUTNYiLXhvg24p+LgNy5IbtxMZBL9eM35fCl6uYkRkZBcXQctMXZ4NklqXA8IQ1OJWbAoGB8LTEdnkuww5PxS6E6NgGWR8VA1P2RPIWosjrBh9QmU3QD6Wa+mZwNN1LXwAdp+eBOKwBPmgO8IYIHz+9EvGPPg5GUXHgxMRO2xCyB+MhItSRfQeRbldxaxAdqPJaI/X1KDvxVJtQl39hwAf2ewMNWADeR7Ndsy2FD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vZGlmeQAyMDE4LTA0LTA0VDE1OjU1OjQ2KzAwOjAwf/qOtQAAAABJRU5ErkJggg==";
const defaultURLs = ['youtibe.com', 'gyoutube.com', 'twutter.com', 'ggmail.com', 'youutube.com', 'outube.com'];
var pageHTML = `

<title>Leo's Popup Finder ` + vers + `</title>
<link rel="icon"
      type="image/png"
      href=` + defaultIcon + `>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<center>


</br>
</br>
<div class="btn-group-vertical">
        <button class="btn btn-primary" onclick="numFinder()">🚨 Popup Generator</button>
		<button class="btn btn-default" onclick="addFinderURL()">➕ Add URL</button>
		<button class="btn btn-default" onclick="removeFinderURL()">🗑️ Remove URL</button>
		<button class="btn btn-default" onclick="showFinderURLs()">📇 Show URLs</button>
		<button class="btn btn-default" onclick="importURLs()">📝 Import URLs</button>
		<button class="btn btn-default" onclick="exportURLs()">📝 Export URLs</button>
		<button class="btn btn-default" onclick="resetFinderURLs()">🔄 Reset URL list to default</button>
</div>
</br>
</br>
</br>
Drag this to your bookmarks bar:
<a href="javascript:(function()%7BopenInNewTab%20%3D%20function(url)%20%7Bvar%20win%20%3D%20window.open(url%2C%20'_blank')%3Bwin.focus()%3B%7D%3BopenInNewTab(%22http%3A%2F%2Fwww.popup.com%2Ffinder%22)%7D)()">Find a Popup</a>
</br>
</br>
<img onclick="window.location.href = 'http://youtube.com/c/LeoTakacs/'" style="margin-top:10px" src="https://dabuttonfactory.com/button.png?t=Subscribe+to+Leo+Takacs&f=Overlock-Bold&ts=24&tc=fff&tshs=1&tshc=000&hp=20&vp=8&c=round&bgt=gradient&bgc=f00&ebgc=c00"></img>

<input type='file' id="upload" accept='.RTCLIST.TXT' onchange='openFile(event)' style="display:none"><br>
    <textarea id="importCont" style="display:none">
    </textarea>

`;
var dummyHTML = `
<title>Searching for a popup......</title>
<link rel="icon"
      type="image/png"
      href=` + defaultIcon + `>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<center>
</br>
Searching for a popup......
`;
var curUrl = 0;
numFinder = function() {
    if (localStorage.getItem("current")) {
        curUrl = parseInt(localStorage.getItem("current"));
    }
    maxUrl = finderURLs.length - 1;
    window.open("http://www." + finderURLs[curUrl], "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=50,left=25,width=1200,height=800");
    if (curUrl == maxUrl) {
        curUrl = 0;
    } else {
        curUrl++;
    }
    localStorage.setItem("current", curUrl);
};
(function() {


    if (window.location.href == 'http://www.popup.com/') {
        document.documentElement.innerHTML = pageHTML;
    } else if (window.location.href == 'http://www.popup.com/finder') {
        document.documentElement.innerHTML = dummyHTML;
            setTimeout(function() {
        if (window.location.href.includes("finder")) {
            numFinder();
            window.close();
        }

    }, 800);
    }

    finderURLs = [];
    for (i = 1; i <= localStorage.getItem("numOfUrls"); i++) {
        spot = "url_" + i;
        console.log(spot);
        finderURLs.push(localStorage.getItem(spot));
    }
    if (!localStorage.getItem("url_1")) {
        finderURLs = [];
        finderURLs = defaultURLs.slice();
        localStorage.setItem("numOfUrls", finderURLs.length);
        for (i = 0; i < finderURLs.length; i++) {
            label = i + 1;
            if (localStorage.getItem("url_" + label) != finderURLs[i]) {
                localStorage.setItem("url_" + label, finderURLs[i]);
            }
        }
    }
    window.onload = function() {
        if (localStorage.getItem("url_1") == null) {
            resetFinderURLs();
        }
    };
})();
importURLs = function() {
    document.getElementById("upload").click();
};
exportURLs = function() {
    var list = '';
    for (var i = 0; i < finderURLs.length; i++) {
        if (i == finderURLs.length - 1) {
            list = list + finderURLs[i];
        } else {
            list = list + finderURLs[i] + ",";
        }
    }
    alert("Exporting URL list as " + spFilename("URLs", "rtclist.txt") + "....");
    download(list, filename);
};
resetFinderURLs = function() {
    alert("Pop-up Generator URL list entries have been reset to default." + " (" + defaultURLs.length + ")");
    localStorage.clear();
    localStorage.setItem("numOfUrls", defaultURLs.length);
    finderURLs = [];
    finderURLs = defaultURLs.slice();
    for (var i = 0; i < finderURLs.length; i++) {
        label = i + 1;
        if (localStorage.getItem("url_" + label) != finderURLs[i]) {
            localStorage.setItem("url_" + label, finderURLs[i]);
        }
    }
};
showFinderURLs = function() {
    o = "";
    o = o + "Saved URLs: \n";
    for (i = 0; i < localStorage.getItem("numOfUrls"); i++) {
        num = i + 1;
        o = o + num + ". " + finderURLs[i] + "\n";
    }
    alert(o);
};
removeFinderURL = function() {
    if (finderURLs.length > 1) {
        var urllist = '';
        for (var i = 0; i < finderURLs.length; i++) {
            num = i + 1;
            urllist = urllist + num + ". " + finderURLs[i] + "\n";
        }
        rem = prompt("Enter number of URL to remove from list:\n\n" + urllist);
        if (rem > finderURLs.length && rem != undefined) {
            alert("URL number " + rem + " does not exist.");
        } else if (rem == '' && rem != undefined) {
            alert("Please enter a URL number." && rem != undefined);
        } else if (rem != undefined) {
            fnum = finderURLs.length - 1;
            alert("www." + finderURLs[rem - 1] + " has been removed from the Pop-up Generator URL list. (" + fnum + ")");
            localStorage.clear();
            rem--;
            finderURLs.splice(rem, 1);
            localStorage.setItem("numOfUrls", finderURLs.length);
            var list = '';
            for (var i = 0; i < finderURLs.length; i++) {
                list = list + finderURLs[i] + "\n";
            }
        }
        for (var i = 0; i < finderURLs.length; i++) {
            label = i + 1;
            if (localStorage.getItem("url_" + label) != finderURLs[i]) {
                localStorage.setItem("url_" + label, finderURLs[i]);
            }
        }
    } else {
        alert("You must have at least one URL.");
    }
};
addFinderURL = function(url, showmsg) {
    if (url == undefined) {
        if (showmsg == undefined) {
            url = prompt("Enter a URL to add to the Pop-up Generator list (without the \'http://\' or \'www.\'):");
        }
    }
    if (url.length > 4) {
        finderURLs.push(url);
        localStorage.setItem("numOfUrls", finderURLs.length);
        if (showmsg == true) {
            alert("www." + url + " has been added to the Pop-up Generator URL list. (" + finderURLs.length + ")");
        }
    } else if (url == null || url == '') {
        if (showmsg == true) {
            alert("Please enter a URL.");
        }
    } else {
        if (showmsg == true) {
            alert("This is not a valid URL");
        }
    }
    for (var i = 0; i < finderURLs.length; i++) {
        label = i + 1;
        if (localStorage.getItem("url_" + label) != finderURLs[i]) {
            localStorage.setItem("url_" + label, finderURLs[i]);
        }
    }
};
openFile = function(event) {
    var input = event.target;
    var reader = new FileReader();
    reader.onload = function() {
        var text = reader.result;
        var node = document.getElementById('importCont');
        node.value = text;
        console.log(reader.result.substring(0, 200));
    };
    reader.readAsText(input.files[0]);
    imFilename = document.getElementById('upload').value;
    imFilename = "C:\\fakepath\\SuperRTC_URLs_5-2-2018-10-57-50.rtclist.txt";
    imFilename = imFilename.replace('C:\\fakepath\\', '');
    document.getElementById('upload').value = '';
    setTimeout(function() {
        var array = document.getElementById("importCont").value.split(',');
        alert("Importing URLs from " + imFilename + "....");
        for (i = 0; i < array.length; i++) {
            addFinderURL(array[i], false);
        }
        alert(i + " URL(s) have been imported to the URL list.");
    }, 700);
};
download = function(data, filename) {
    var file = new Blob([data], {
        type: "text/plain;charset=utf-8"
    });
    if (window.navigator.msSaveOrOpenBlob) // IE10+
        window.navigator.msSaveOrOpenBlob(file, filename);
    else { // Others
        var a = document.createElement("a"),
            url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
        }, 1);
    }
};
spFilename = function(text, ext) {
    var d = new Date();
    //
    var mo = d.getMonth() + 1;
    var day = d.getDay() - 1;
    var year = d.getFullYear();
    //
    var n = d.getTime();
    var h = d.getHours();
    var m = d.getMinutes();
    var s = d.getSeconds();
    filename = "SuperRTC_" + text + "_" + mo + "-" + day + "-" + year + "-" + h + "-" + m + "-" + s + "." + ext;
    return filename;
};


window.onload = function() {

};