// ==UserScript==
// @name V2EXcellent.js
// @namespace http://vitovan.github.io/v2excellent.js/
// @version 1.1.11
// @description A Better V2EX
// @author VitoVan
// @include http*://*v2ex.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it/8.4.2/markdown-it.min.js
// @grant none
// @downloadURL https://update.greasyfork.icu/scripts/14182/V2EXcellentjs.user.js
// @updateURL https://update.greasyfork.icu/scripts/14182/V2EXcellentjs.meta.js
// ==/UserScript==
$('document').ready(function() {
window.loaded = true;
});
var POST_PROCESS_FUNCS = [
function done() {
console.log('V2EXcellented!');
},
];
//Fix night mode
var divWrapper = document.getElementById("Wrapper");
if(divWrapper.className == 'Night'){
divWrapper.style.backgroundColor ='#00000000';
divWrapper.style.backgroundImage ="url('/static/img/shadow.png'), url('//static.v2ex.com/bgs/pixels.png')";
}
// markdown-it 初始化
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
}
});
// 图片链接自动转换成图片 代码来自caoyue@v2ex
POST_PROCESS_FUNCS.push(function linksToImgs() {
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) &&
!/
";
}
}
});
// 回复内容做markdown渲染
POST_PROCESS_FUNCS.push(function mdRender() {
$(".reply_content").each(function(index, item) {
var replyContent = $(item).html();
replyContent = replyContent.replace(/
/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 Post Processing: ' + f.name);
}
});
}
var language = (
window.navigator.userLanguage || window.navigator.language
).toLowerCase();
var currentLocation = location.href;
//If this is the thread page
if (currentLocation.match(/\/t\/\d+/g)) {
//Enable Reply Directly Feature
$('div.topic_buttons').append(
' 回复',
);
//Enable Img Uploader Feature
enableUploadImg();
var comments = [];
//loading
showSpinner();
//Get comments from current page
fillComments($('body'));
//Get other pages comments
var CURRENT_PAGE_URLS = [];
$('a[href].page_normal').each(function(i, o) {
if (CURRENT_PAGE_URLS.indexOf(o.href) === -1) {
CURRENT_PAGE_URLS.push(o.href);
}
});
var LEFT_PAGES_COUNT = CURRENT_PAGE_URLS.length;
var CURRENT_PAGE = 0;
var DOMS = [$(document)];
if (LEFT_PAGES_COUNT > 0) {
$(CURRENT_PAGE_URLS).each(function(i, o) {
$.get(o, function(result) {
var resultDom = $('