// ==UserScript== // @name 扇贝爬取 // @namespace http://tampermonkey.net/ // @version 0.5 // @description try to take over the world! // @author Checkmate // @match *://web.shanbay.com/* // @icon https://www.google.com/s2/favicons?domain=shanbay.com // @grant unsafeWindow // ==/UserScript== var $ = unsafeWindow; var english; var chinese; var index; var end; var timer; var timer1; var timer2; var op = 0; var flag = 0; var radio_flag = 0; var o =document.createElement("input"); o.type = "button"; o.value = "开始"; o.style.width = "80px"; o.style.height = "40px"; o.style.margin = "2.5px 0px 0px 2px"; document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(o); var oo =document.createElement("input"); oo.type = "button"; oo.value = "清空"; oo.style.width = "80px"; oo.style.height = "40px"; oo.style.margin = "2.5px 0px 0px 2px"; document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(oo); var radio =document.createElement("input"); radio.setAttribute("id","radio"); radio.type = "radio"; radio.style.margin = "15.5px 0px 0px 5px"; radio.addEventListener("click",check); document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(radio); var o2 =document.createElement("div"); o2.innerHTML = "爬取释义" o2.style.margin = "10.5px 0px 0px 3px"; document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(o2); var content=document.createElement("textarea"); content.setAttribute("id","content"); content.setAttribute("disabled","true"); content.style.width = "1320px"; document.getElementsByClassName("Layout_main__2_zw8")[0].appendChild(content); var leaf = 0; var count = 0; var countArea=document.createElement("div"); countArea.innerHTML = "当前爬取数量:" + count; countArea.style.margin = "10.5px 0px 0px 15px"; document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(countArea); var o3 =document.createElement("input"); o3.type = "button"; o3.value = "复制"; o3.style.width = "80px"; o3.style.height = "40px"; o3.style.margin = "2.5px 0px 0px 250px"; document.getElementsByClassName("SubNav_itemsWrapper__1mM4u")[0].appendChild(o3); function check(){ if(radio_flag == 0){//选中 flag = 1; radio_flag = 1; }else if(radio_flag == 1){ flag = 0; radio_flag = 0; radio.checked = false; } } function initialize(){ oo.addEventListener("click",clear); o3.addEventListener("click",copyText); timer = setInterval(function(){ var url = window.location.href; if( url == "https://web.shanbay.com/wordsweb/#/collection"){//生词本 o.removeEventListener("click",begin_wordText); o.addEventListener("click",begin_newWordText); }else if ( url == "https://web.shanbay.com/wordsweb/#/words-table"){ o.removeEventListener("click",begin_newWordText); o.addEventListener("click",begin_wordText); } },300); } function copyText(){ if(content.innerHTML != ""){ content.select(); document.execCommand("copy"); alert("复制完成"); } } function clear(){ content.innerHTML = ""; count = 0; countArea.innerHTML = "当前爬取数量:" + count; } function copy_wordText(){ timer1 = setInterval(function(){ end = $.document.getElementsByTagName("li"); var last = parseInt(end[end.length - 2].innerHTML); var res = end[end.length - 1]; var str=""; english = $.document.getElementsByClassName("index_wordName__1lkbV"); chinese = $.document.getElementsByClassName("index_bottom__XLoPQ"); if(flag == 0){ for(var i=0;i",""); temp = temp.replaceAll("",""); temp = temp.replaceAll("",""); str += english[j].innerHTML + " " + temp + '\n'; count++; } } content.innerHTML += str; countArea.innerHTML = "当前爬取数量:" + count; leaf++; if(leaf < last){ res.click(); }else{ o.value = "开启";//close clearInterval(timer1); op = 0; leaf = 0; } },500); } function copy_newWordText(){ timer2 = setInterval(function(){ end = $.document.getElementsByTagName("li"); var last = parseInt(end[end.length - 2].innerHTML); var res = end[end.length - 1]; var str=""; english = $.document.getElementsByClassName("CollectionList_word__7zQwd"); chinese = $.document.getElementsByClassName("CollectionList_definitionCn__3MoTq"); if(flag == 0){ for(var i=0;i",""); temp = temp.replaceAll("",""); str += english[j].innerHTML + " " + temp + '\n'; count++; } } content.innerHTML += str; countArea.innerHTML = "当前爬取数量:" + count; leaf++; if(leaf < last){ res.click(); }else{ o.value = "开启";//close clearInterval(timer2); op = 0; leaf = 0; } },500); } function begin_wordText(){ if(op == 0){ o.value = "爬取中...";//open copy_wordText(); op = 1; } } function begin_newWordText(){ if(op == 0){ o.value = "爬取中...";//open copy_newWordText(); op = 1; } } initialize();