Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Asukafag's Zerochan Links Grabber
- // @namespace http://dobrochan.org/
- // @version 0.01
- // @description Helps you grab links to images with specified tag from Zerochan.
- // @author Asukafag
- // @include http://www.zerochan.net/*
- // @noframes
- // ==/UserScript==
- (function() {
- var d;
- var tag = "Souryuu+Asuka+Langley";
- var page = 1;
- var site = "http://zerochan.net";
- var parser = new DOMParser();
- var links = new Array();
- var list;
- var data;
- var count;
- var gotList = new CustomEvent("_dGotList");
- var box = '<div id="_dWrapper"><div id="_downloader_box" style="Background-color: #000000;height: 100%;width: 100%;opacity: 0.3;position: fixed;z-index: 4;"> </div> <div id="_downloader" style="background-color: #FFFFFF;position: fixed;width: 500px;top: 50%;margin-top: -244px;left: 50%;margin-left: -300px;border: 2px solid blue;border-radius: 25px;padding-top: 25px;padding-bottom: 25px;padding-left: 45px;padding-right: 45px;z-index: 5;opacity: 1;font-family: Tahoma, Verdana;"> <div id="title" style="font-size: 25px; color: #ca7272; text-align: center; margin-bottom: 15px;"> Asukafag′s Zerochan Links Grabber</div> <div id="description" style="font-size: 13px; text-align: center; margin-bottom: 25px;"> Копирование ссылок на изображения по тегам</div> <div style="font-size:12px;display: inline;">Тег:</div> <input type="text" id="tag" placeholder="Souryuu Asuka Langley" style=" margin-bottom: 25px; "> <div id="process" style=" font-size: 12px; opacity: 0.3; margin-bottom: 5px;"></div> <div id="loading" style=" min-height: 30px; width: 100%; background-color: #009688; margin-bottom: 15px; border: 2px solid #009688;"> <div id="loaded" style=" background-color: #9ff354; min-height: 30px; width: 0%;"></div> </div> <textarea name="" id="" cols="30" rows="10" style="width: 80%;margin: 0 auto;display: block;height: 260px;resize: none;margin-bottom: 20px;"></textarea> <div style="clear:both"></div> <button id="_dStart">Поехали!</button> <button id="_dClose">Закрыть</button></div></div>';
- var shortcut = '<a id="_dShortcut" href="javascript:void(0);" style="opacity:0.7" onmouserover="this.style.opacity=1;" onmouseleave="this.style.opacity=0.7"> <div style=" font-family: Helvetica, Verdana; font-weight: bold; font-size: 18px; color: #71d266; background-color: #fff1c8; width: 60px; text-align: center; padding: 3px; border-radius: 15px 15px 0px 0px; border: 2px solid #f3e4b8; position: fixed; top: 100%; margin-top: -30px; left: 100%; margin-left: -75px; "><div style=" display: inline; color: #e22d2d; ">A</div>ZLG</div></a>';
- function updateBar(current, total){
- document.getElementById("loaded").style.width=Math.floor(current/(total/100))+"%";
- }
- function updateStatus(str){
- document.getElementById("process").innerHTML = str;
- }
- function addLink(link){
- document.getElementById("_downloader").getElementsByTagName("textarea")[0].value += link+"\r\n";
- }
- function loadList(){
- if (d.getElementById("children")) {
- updateStatus("Это <a href='http://zerochan.net/"+tag+"' style='text-decoration:underline'>неполный тег</a>.");
- return;
- }
- list = d.getElementById("thumbs2").getElementsByTagName("li");
- for (var a=0; a<list.length; a++) {
- links.push(list[a].getElementsByTagName("a")[0].getAttribute("href"));
- }
- updateBar(page, count);
- if (page < count) {
- page++;
- loadPage(tag+"?p="+page);
- }
- else {
- page = 0;
- count = links.length-1;
- document.removeEventListener("_dReady", loadList);
- document.addEventListener("_dReady", getLinks);
- document.dispatchEvent(gotList);
- loadPage(links[0]);
- updateStatus("Копируем ссылки...");
- }
- }
- function getLinks(){
- var link;
- a = d.getElementById("large").getElementsByTagName("img")[0];
- if (a.parentNode.tagName == "A") link = a.parentNode.getAttribute("href");
- else link = a.getAttribute("src");
- updateBar(page+1, count+1);
- addLink(link);
- if (page < count) {
- page++;
- console.log(page+" from "+links.length);
- loadPage(links[page]);
- }
- else {
- console.log(links);
- updateStatus("Готово!");
- }
- }
- function loadPage(url) {
- console.log("url: "+url);
- xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.onreadystatechange = (function(){
- if (xhr.readyState != 4) return;
- if (xhr.status == "404") {
- updateStatus("Такого тега нет.");
- return;
- }
- d = parser.parseFromString(xhr.responseText, "text/html");
- document.dispatchEvent(new CustomEvent("_dReady"));
- });
- xhr.send();
- }
- function getCount(){
- updateStatus("Получаем информацию о количестве ссылок....");
- console.log("getCount");
- var p = d.getElementById("content").getElementsByTagName("p");
- p = p[p.length-1];
- console.log(p);
- count = Number(p.innerHTML.match(/из ([0-9]+?.)/i)[1]);
- document.removeEventListener("_dReady", getCount);
- document.addEventListener("_dReady", loadList);
- document.dispatchEvent(new CustomEvent("_dReady"));
- }
- function copyLinks() {
- if (document.getElementById("tag").value.length > 0) tag = document.getElementById("tag").value.replace(/ /ig, "+");
- document.addEventListener("_dReady", getCount);
- loadPage(tag);
- }
- function displayModule(){
- document.getElementsByTagName("body")[0].removeChild(document.getElementById("_dShortcut"));
- document.getElementsByTagName("body")[0].innerHTML = box+document.getElementsByTagName("body")[0].innerHTML;
- document.getElementById("_dStart").addEventListener("click", copyLinks);
- document.getElementById("_dClose").addEventListener("click", function(){
- displayShortcut();
- document.getElementsByTagName("body")[0].removeChild(document.getElementById("_dWrapper"));
- });
- }
- function displayShortcut(){
- console.log("displayed");
- document.getElementsByTagName("body")[0].innerHTML += shortcut;
- var elem = document.getElementById("_dShortcut");
- elem.addEventListener("click", displayModule);
- elem.addEventListener("mouseover", function(){elem.style.opacity="1"});
- elem.addEventListener("mouseleave", function(){elem.style.opacity="0.7"});
- }
- window.addEventListener('load', function() {
- displayShortcut();
- }, false);
- loaded = true;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement