Last active
July 8, 2020 22:33
-
-
Save mysteriouss/7a0f2215bfe3a130f6ad40eb5099b07b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name V2EXcellent.js-Extra | |
// @namespace none | |
// @version 1.0.0 | |
// @description A Better V2EX - Extra | |
// @author mysteri0uss | |
// @match *://*.v2ex.com/* | |
// @require //code.jquery.com/jquery-1.12.4.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.4.2/markdown-it.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_deleteValue | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
$('document').ready(function() { | |
window.loaded = true; | |
}); | |
var POST_PROCESS_FUNCS = [ | |
function done() { | |
console.log('V2EXcellented Extra!'); | |
}, | |
]; | |
POST_PROCESS_FUNCS.push(function linksToImgs() { | |
/* | |
* in order to work with V2EXcellent.js | |
* migrate linksToImgs function to V2EXcellent.js mannually | |
* uncomment this return, after the migration | |
*/ | |
//return; | |
function replaceImage(image){ | |
var imageParent = image.parentElement; | |
var imageSrc = image.src.replace(/^http:/,"https:"); | |
if(-1 != imageSrc.indexOf('sinaimg')){ | |
imageSrc = imageSrc.replace("http://ws","https://ww"); | |
imageSrc = imageSrc.replace("https://ws","https://ww"); | |
} | |
imageParent.removeChild(image); | |
imageParent.innerHTML += | |
"<img src='" + imageSrc + "' " | |
+ "rel='noreferrer' referrerpolicy='no-referrer' refererpolicy='no-referrer' />"; | |
} | |
try{ | |
var links = document.links; | |
for (var x in links) { | |
var link = links[x]; | |
if ( | |
/^http.*\.(?:jpg|jpeg|jpe|bmp|png|gif)/i.test(link.href) && | |
!/<img\s/i.test(link.innerHTML) | |
) { | |
var imageSrc = link.href; | |
if(-1 != imageSrc.indexOf('sinaimg')){ | |
imageSrc = imageSrc.replace("http://ws","https://ww"); | |
imageSrc = imageSrc.replace("https://ws","https://ww"); | |
} | |
link.innerHTML = | |
"<img title='" + link.href + "' src='" + link.href + "' />"; | |
} | |
} | |
}catch(e){ | |
} | |
var meta = document.querySelector('meta[name="Referrer"]'); | |
if(meta){ | |
meta.setAttribute("content", 'no-referrer'); | |
}else{ | |
meta = document.querySelector('meta[name="referrer"]'); | |
if(meta){ | |
meta.setAttribute("content", 'no-referrer'); | |
}else{ | |
meta = document.createElement('meta'); | |
meta.name = "referrer"; | |
meta.content = "no-referrer"; | |
document.getElementsByTagName('head')[0].appendChild(meta); | |
} | |
} | |
var images = document.images; | |
for (var y in images) { | |
var image = images[y]; | |
if ( | |
/^http:\/\/.*\.(?:jpg|jpeg|jpe|bmp|png|gif)/i.test(image.src) | |
) { | |
if(-1 == image.src.indexOf('sinaimg')){ | |
continue; | |
} | |
console.log('1: '+image.src); | |
replaceImage(image); | |
}else if ( | |
/^https:\/\/.*\.(?:jpg|jpeg|jpe|bmp|png|gif)/i.test(image.src) | |
) { | |
//console.log(image.src); | |
if( | |
(-1 == image.src.indexOf('v2ex.co')) | |
){ | |
console.log('2: '+image.src); | |
replaceImage(image); | |
} | |
}else{ | |
console.log('3: '+image.src); | |
} | |
} | |
}); | |
POST_PROCESS_FUNCS.push(function markRed() { | |
var username_in_infopage; | |
var listName = 'red-list'; | |
var strlist = GM_getValue(listName, ""); | |
var redlist = strlist.split(';'); | |
var url = document.URL; | |
var path = location.pathname | |
var buttonName = 'redbutton'; | |
//console.log(path); | |
{ | |
//show all | |
//console.log('list:' + GM_getValue('red-list', 'empty')); | |
// delete all | |
//GM_deleteValue('red-list');console.log('list:' + GM_getValue('red-list', 'empty'));return; | |
if (path.startsWith('/t/')) { | |
// detail page | |
let comments = document.getElementsByClassName('cell'); | |
let len = comments.length; | |
for(let i=0; i<len; i++) { | |
if (comments[i].id.substr(0, 2) != 'r_') { | |
continue; | |
} | |
let username = comments[i].getElementsByTagName('strong')[0]; | |
//console.log(username.innerText); | |
if (redlist.indexOf(username.innerText) >= 0) { | |
console.log('in red list: ' + username.innerText); | |
comments[i].style = "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;"; | |
} | |
} | |
} | |
} | |
}); | |
POST_PROCESS_FUNCS.push(function mdRender() { | |
var md = window.markdownit({ | |
html: true, | |
linkify: true, | |
breaks: true, | |
langPrefix: "hljs ", | |
highlight: function (str, lang) { | |
if (lang && hljs.getLanguage(lang)) { | |
try { | |
return hljs.highlight(lang, str).value; | |
} catch (__) { } | |
} | |
return ''; // use external default escaping | |
} | |
}); | |
$(".reply_content").each(function(index, item) { | |
var replyContent = $(item).html(); | |
if(-1 != replyContent.indexOf('<img')) return; | |
replyContent = replyContent.replace(/<br\s*\/?>/gi,"\r\n"); | |
$(item).html(md.render(replyContent)); | |
}); | |
}); | |
function postProcess() { | |
$(POST_PROCESS_FUNCS).each(function(i, f) { | |
if (typeof f === 'function') { | |
f(); | |
console.log('V2EXcellent Extra Post Processing: ' + f.name); | |
} | |
}); | |
} | |
postProcess(); | |
})(); |
好像失效了,请问你的还正常使用?
做了下调整,可以试试
如果使用了 V2EXcellent.js ,手动 merge 下 linksToImgs 的代码
另外 <meta name="Referrer" content="no-referrer">
影响网站登录
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
好像失效了,请问你的还正常使用?