// ==UserScript== // @name 知乎-匿名提问者标注 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 在问题页, 标注匿名提问, 防止钓鱼 // @author C4r // @match https://www.zhihu.com/* // @require https://cdn.jsdelivr.net/npm/jquery@3.5.0/dist/jquery.min.js // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; function isHome() { return $("#TopstoryContent").length > 0 } function isQuestionPage() { return $('.QuestionPage').length > 0 } function isAuthorPage() { return $('#ProfileHeader').length > 0 } function getLogURL(questionURL) { // return new URL('log', questionURL).href return questionURL + '/log' } function httpGetAsync(theUrl, callback) { var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) callback(xmlHttp.responseText); } xmlHttp.open("GET", theUrl, true); // true for asynchronous xmlHttp.send(null); } function getAuthorUrl(logURL) { return new Promise((resolve, reject) => { httpGetAsync(logURL, (responseText) => { // console.log('get response') let repHTML = $.parseHTML(responseText) let author = $(repHTML).find('.zm-item:last > div > a').attr('href') if (author != undefined) { let userInfo = { 'name': $(repHTML).find('.zm-item:last > div > a').text(), 'url': $(repHTML).find('.zm-item:last > div > a').get(0).href, 'a': $(repHTML).find('.zm-item:last > div > a').get(0).outerHTML } resolve(userInfo) } else { // console.log( '匿名提问 : ', undefined) resolve(undefined) } }) }) } class Author { constructor(url) { this.url = url this.name = undefined this.avatar = undefined this.isOrg = undefined this.isVerified = undefined this.ask = undefined this.answer = undefined // 关注了 this.following = undefined // 关注者 this.follower = undefined this.post = undefined this.agree = undefined this.score = undefined this.scoreMarker = undefined } print() { console.log('url : ', this.url) console.log('name : ', this.name) console.log('avatar : ', this.avatar) console.log('isOrg : ', this.isOrg) console.log('isVerified : ', this.isVerified) console.log('ask : ', this.ask) console.log('answer : ', this.answer) console.log('following : ', this.following) console.log('follower : ', this.follower) console.log('post : ', this.post) console.log('agree : ', this.agree) console.log('score : ', this.score) } updateAuthorFromPage(pageHTML) { this.name = $(pageHTML).find('.ProfileHeader-name').text() this.avatar = $(pageHTML).find('img.Avatar').attr('src') this.ask = parseInt($(pageHTML).find('.Profile-mainColumn li.Tabs-item[aria-controls="Profile-asks"] span').text()) this.answer = parseInt($(pageHTML).find('.Profile-mainColumn li.Tabs-item[aria-controls="Profile-answers"] span:eq(0)').text()) + parseInt($(pageHTML).find('.Profile-mainColumn li.Tabs-item[aria-controls="Profile-answers"] span:eq(1)').text()) this.post = parseInt($(pageHTML).find('.Profile-mainColumn li.Tabs-item[aria-controls="Profile-posts"] span').text()) this.following = parseInt($(pageHTML).find('.FollowshipCard a:eq(0) .NumberBoard-itemValue').attr('title')) this.follower = parseInt($(pageHTML).find('.FollowshipCard a:eq(1) .NumberBoard-itemValue').attr('title')) let arrayAgree = $($(pageHTML).find('.Zi--Like').closest('.css-12ofpn8').find('.css-vurnku').contents().get(0)).text().match(/\d+/g) if(arrayAgree){ this.agree = parseInt(arrayAgree.join('')) }else{ this.agree = 0 } // this.agree = parseInt($($(pageHTML).find('.Zi--Like').closest('.css-12ofpn8').find('.css-vurnku').contents().get(0)).text().match(/\d+/g).join('')) } /** * 评估作者 * @returns 1-10 */ evaluateAuthor() { let score = 5 if (this.agree >= 1.1 * this.answer) { score = score + 1 // Math.ceil( this.agree/this.answer ) // console.log('agree up') } else if (this.agree <= 0.2 * this.answer) { score = score - 2 // console.log('agree down') } else if (this.answer <= 0.5 * this.ask) { score = score - 1 } if (this.answer >= 1.5 * this.ask) { score = score + 1 // console.log('answer up') } else if (this.answer <= 0.2 * this.ask) { score = score - 2 } else if (this.answer <= 0.7 * this.ask) { score = score - 1 } if (this.follower < 100) { score = score - 1 // console.log('follower up') } if (this.follower >= 100) { score = score + 1 // console.log('follower up') } if (this.follower >= 1000) { score = score + 2 } if (score > 10) { score = 10 } else if (score < 1) { score = 1 } this.score = score if (this.score > 6) { this.scoreMarker = '☼' } else if (this.score < 4) { this.scoreMarker = '🔥' } else { this.scoreMarker = '☉' } } } /** * * @param {str} authorUrl 作者页链接 * https://www.zhihu.com/org/guan-cha-zhe-wang-31 <- 官方帐号 * https://www.zhihu.com/people/liaoxuefeng <- 个人帐号 * @returns {Author} author * */ function getAuthorInfoDetail(authorUrl) { return new Promise((resolve, reject) => { httpGetAsync(authorUrl, (responseText) => { // console.log('get response') let repHTML = $.parseHTML(responseText) let author = new Author(authorUrl) author.updateAuthorFromPage(repHTML) author.evaluateAuthor() resolve(author) }) }) } function topic() { return '\