javascript 蜘蛛制壶,tpc_index
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 蜘蛛制壶,tpc_index相关的知识,希望对你有一定的参考价值。
// ==UserScript==
// @name 0zhihu-tpc_index-0.1
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.zhihu.com/topic/*/index
// @grant none
// ==/UserScript==
(function() {
setTimeout(do1, 3 * 1000);
// do1()
function do1() {
main1()
}
function main1() {
var tpc1 = document.querySelector('div.ContentItem.TopicMetaCard-item h2.ContentItem-title div').innerText.replace('\n', '')
var qstn1 = ''
//
qstn1+=tpc1+'\n'
//
var frame_1 = document.querySelectorAll('div.TopicIndexModule')
for (var i = 0; i < frame_1.length; i++) {
var title1 = frame_1[i].querySelector('h2.TopicIndexModule-title').innerText.replace('\n', '')
//
qstn1 += ['',title1].join('\t')+'\n'
//
var tpc_sub = frame_1[i].querySelectorAll('div.TopicIndexModule-item a')
for (var i2 = 0; i2 < tpc_sub.length; i2++){
var title_qstn1 = tpc_sub[i2].innerText.replace('\n', '')
var url_qstn1= tpc_sub[i2]['href'];
// var url_qstn1= ''+tpc_sub[i2].getAttribute('href');
// ----------
// ---数据库式记录
// qstn1 += [tpc1,title1,title_qstn1,url_qstn1].join('\t')+ '\n'
// ---目录结构式记录
qstn1 += ['','',title_qstn1,url_qstn1].join('\t')+ '\n'
// ----------
}
}
//
var tpc_rltv1 = ''
var frame_1 = document.querySelectorAll('div.TopicIndexModule')
for (var i = 0; i < frame_1.length; i++) {
var title1 = frame_1[i].querySelector('h2.TopicIndexModule-title').innerText.replace('\n', '')
var tpc_rltv = frame_1[i].querySelectorAll('a.TopicLink')
for (var i2 = 0; i2 < tpc_rltv.length; i2++){
var title_tpc1 = tpc_rltv[i2].innerText.replace('\n', '')
var url_tpc1= tpc_rltv[i2]['href'];
// var url_tpc1= 'https:'+tpc_rltv[i2].getAttribute('href');
tpc_rltv1 += [tpc1,title1,title_tpc1,url_tpc1].join('\t') + '\n'
}
}
//
var tpc_up_a_dn = ''
var frame_1 = document.querySelectorAll('div.TopicRelativeBoard-item')
for (var i = 0; i < frame_1.length; i++) {
var title1 = (i == 0) ? 'tpc_up' : 'tpc_dn'
var tpc_rltv = frame_1[i].querySelectorAll('div.TopicTagsContainer a')
for (var i2 = 0; i2 < tpc_rltv.length; i2++){
var title_tpc1 = tpc_rltv[i2].innerText.replace('\n', '')
var url_tpc1= tpc_rltv[i2]['href'];
// var url_tpc1= 'https:'+tpc_rltv[i2].getAttribute('href');
tpc_up_a_dn += [tpc1, title1, title_tpc1 ,url_tpc1].join('\t')+'\n'
}
}
// ----------
// var l1 = [qstn1,tpc_rltv1,tpc_up_a_dn]
// var l2 = ['分支的提问','每个分支的关联话题','父子话题','','','']
// for (var i = l1.length-1; i >= 0; i--){
// again1(i+1,l1[i],l2[i])
// }
// ---
var dic1={
'分支的提问':qstn1,
'每个分支的关联话题':tpc_rltv1,
'父子话题':tpc_up_a_dn
//
}
var l1 = Object.keys(dic1)
for (var i = l1.length-1; i >= 0; i--){
again1(i+1,dic1[l1[i]],l1[i])
}
// ----------
}
function selText(textarea_id) {
// console.clear();
// textarea_id = 'copy3';
document.getElementById(textarea_id).select();
try {
if (document.execCommand('copy', false, null)) {
// if(document.execCommand('copy', false, null)){
console.log('success')
//success info
} else {
console.log('fail')
//fail info
}
} catch (err) {
console.log(err)
//fail info
}
}
// function again1(textarea_id,input_id,input_id2,span1_id,str1,str2) {
function again1(i,str1,str2) {
var span_id='cp'+(i)+'1'
var input_id2='cp'+(i)+'2'
var textarea_id='cp'+(i)+'3'
var input_id='cp'+(i)+'4'
//
var body = document.getElementsByTagName('body')[0];
var span1 = document.getElementById(span_id)
var textarea1, btn_1, btn_2,div1
//
if (span1){
body.removeChild(span1)
}
//
textarea1 = document.createElement("textarea");
// textarea1.innerHTML = text;
textarea1.setAttribute('id', textarea_id);
textarea1.setAttribute('cols', '80');
textarea1.setAttribute('rows', '10');
textarea1.style.cssText ='font-size:15px;'
//
btn_1 = document.createElement("input");
btn_1.setAttribute('id', input_id);
btn_1.setAttribute('type', 'button');
btn_1.setAttribute('value', 'cp');
btn_1.style.cssText = ' -webkit-appearance: button; box-sizing: border-box; width:28px; height: 120px; position: absolute;'
//
btn_2 = document.createElement("input");
btn_2.setAttribute('id', input_id2);
btn_2.setAttribute('value', ' '+str2);
btn_2.setAttribute('readonly', 'true');
btn_2.setAttribute('size', '10');
//
div1 = document.createElement("div");
//
span1 = document.createElement("span");
span1.setAttribute('id', span_id);
// if
span1.style.cssText = 'display:inline-block;margin:0px 16px 0px 12px';//btn_1的width是28px
// span1.style.margin='0px 12px 0px 2px'
//
div1.insertBefore(btn_2,div1.childNodes[0])
var l_tmp = [btn_1,textarea1,div1];
for (i = 0;i < l_tmp.length;i++){
span1.insertBefore(l_tmp[i],span1.childNodes[0]);
}
body.insertBefore(span1, body.childNodes[0]);
// body.insertBefore(btn_1, body.childNodes[0]);
// body.insertBefore(textarea1, body.childNodes[0]);
// body.insertBefore(btn_2, body.childNodes[0]);
//
// var textarea1 = document.getElementById(textarea_id)
textarea1.innerHTML = str1
//此处不能用innerText,否则\n会被转换为<br>
// document.querySelector('input#'+input_id).addEventListener('click', function() {selText()})
btn_1.addEventListener('click', function() {selText(textarea_id)})
}
})();
以上是关于javascript 蜘蛛制壶,tpc_index的主要内容,如果未能解决你的问题,请参考以下文章