// ==UserScript== // @name NGA Excel // @author 风昔 // @description 原userscripts-mirror上风昔大大的NGA Excel,简单更新了部分代码使之可用。 // @version 1.1.3 // @match http://bbs.ngacn.cc/* // @include http://bbs.ngacn.cc/* // @match http://nga.178.com/* // @include http://nga.178.com/* // @match http://bbs.nga.cn/* // @include http://bbs.nga.cn/* // @run-at document-start // @namespace https://greasyfork.org/users/179759 // @downloadURL https://update.greasyfork.icu/scripts/40576/NGA%20Excel.user.js // @updateURL https://update.greasyfork.icu/scripts/40576/NGA%20Excel.meta.js // ==/UserScript== (function(){ 'use strict'; var body0, body1, parent0, title0, status0, style, statusMap ={ none : 'normal', normal : 'none', clean : 'none' }, createDom = function(html) { var tmp = document.createElement("div"); tmp.innerHTML = html; return tmp.childNodes[0]; }, setCookie = function(c_name,value, expire){ var expiredays = expire || 1; var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); }, getCookie = function(c_name) { var cookies = document.cookie.split(';'); var cookie = ''; for ( var i = 0; i < cookies.length; i++) { cookie = cookies[i].split('='); if (cookie[0].replace(/^\s+|\s+$/g, '') == c_name) { return (cookie.length <= 1) ? "" : unescape(cookie[1].replace( /^\s+|\s+$/g, '')); } } return ""; }, removeClass = function(dom){ dom.className = ""; for(var i =0; i< dom.children.length;i++){ removeClass(dom.children[i]); } return dom; },generate = function(to) { var rowCount = -1, frame = createDom('
'), threadsTable = createDom('
'), rootNav = createDom('NGA'), newRow = function(ctx){ var rowDom =document.createElement("tr"), rowHTML = '' + ( rowCount< 1 ? '' : rowCount ) + ''; rowCount++; for(var i = 0; i < ctx.length; i++){ rowHTML += ''; } rowDom.innerHTML = rowHTML; rowDom.children[rowDom.children.length-1].removeAttribute("width"); for(var i = 0; i < ctx.length; i++){ if(typeof ctx[i] == "string"){ rowDom.children[i+1].textContent = rowDom.children[i+1].innerText = ctx[i]; }else{ rowDom.children[i+1].appendChild(ctx[i].cloneNode(true)); } } threadsTable.appendChild(rowDom); },getAnchor = function(tb, type){ if(tb instanceof Array){ tb = tb[0]; } var args, scripts = tb.getElementsByTagName("script"), anchor = createDom("REPLY"); try{ for(var i = 0; i < scripts.length; i++){ if(/commonui\.postArg\.proc/.test(scripts[i].innerHTML)){ args = scripts[i].innerHTML.replace(/^[^(]*\(|\s*/g,"").split(","); break; } } if(type == 1){ anchor.setAttribute("href","/post.php?action=reply&_newui&fid="+ args[8] +"&tid=" + args[9]); }else{ anchor.setAttribute("href","/post.php?action=quote&_newui&fid="+ args[8] +"&tid=" + args[9] + "&pid=" + args[10] + "&article="+ args[0]); } }catch(e){ return tb.nextElementSibling ? getAnchor(tb.nextElementSibling, type) : anchor; } return anchor; }; frame.appendChild(threadsTable); if(window.location.pathname == "/thread.php"){ var dom=document.getElementById("topicrows"), nav0 = document.getElementById("m_pbtntop").getElementsByTagName("a"), nav1 = document.createElement("div"), topics = dom.children[1].children, ctx; for(var i = 0; i< nav0.length;i++){ if(!isNaN(Number(nav0[i].textContent))){ nav1.appendChild(nav0[i].cloneNode(true)); } } newRow(["", "", rootNav, nav1]); newRow(["REPLIES","STARTER", "LAST POST", ""]); for ( var i = 0; i < dom.children.length; i+=2) { ctx= []; var str=dom.children[i].children[0].children[1].children[1].textContent; var item=dom.children[i].children[0].children[1].children[0]; if(str.charAt(str.length - 1)!="•" ){item=dom.children[i].children[0].children[1].children[1];} ctx.push(item); ctx.push(dom.children[i].children[0].children[2].children[0].textContent); /*ctx.push(topics[i].children[0].textContent); ctx.push(topics[i].children[2].children[0].textContent); ctx.push(topics[i].children[3].children[1].textContent); var threadCtx = topics[i].children[1].children, threadNew = createDom('
'); for(var j= 0; j < threadCtx.length; j++){ threadNew.appendChild(removeClass(threadCtx[j].cloneNode(true))); } ctx.push(threadNew);*/ ctx.push(dom.children[i].children[0].children[3].children[0].textContent); ctx.push(""); newRow(ctx); } newRow(["", "", rootNav, nav1]); } else if(window.location.pathname == "/read.php"){ var nav0 = [], nav1 = document.createElement("div"), navAnchors0 = document.getElementById("m_pbtntop").getElementsByTagName("a"), navAnchors1 = document.getElementById("m_nav").getElementsByTagName("a"), postTables = (function() { var tables = document.getElementsByTagName("table"), res = [], i = 0; for (; i < tables.length; i++) { if (tables[i].className == "forumbox postbox") { res.push(tables[i]); } } return res; })(), startIndex = Number(postTables[0].getElementsByTagName("tr")[0].getAttribute("id").substr(10)); for(var i = 1; i< navAnchors1.length;i++){ if (navAnchors1[i].className == "nav_link") { navAnchors1[i].className ="uitxt1"; nav0.push(navAnchors1[i].cloneNode(true)); } } nav1.appendChild(nav0[nav0.length-1]); for(var i = 0; i< navAnchors0.length;i++){ if(!isNaN(Number(navAnchors0[i].textContent))){ nav1.appendChild(navAnchors0[i].cloneNode(true)); } } nav1.appendChild(getAnchor(postTables, 1)); newRow([rootNav,nav0[0],nav1]); newRow(["AUTHOR","TIME", "CONTENT"]); for ( var i = startIndex; i < postTables.length + startIndex; i++) { try{ var ctx = []; ctx.push(document.getElementById("postauthor" + i).textContent); ctx.push(document.getElementById("postdate" + i).textContent); ctx.push(document.getElementById("postcontent" + i).cloneNode(true)); ctx[2].appendChild(getAnchor(postTables[i-startIndex])); newRow(ctx); }catch(e){ } } newRow([rootNav,nav0[0],nav1]); } else{ rowCount = 1; var rowCtx = [],hrefs = document.getElementsByTagName("a"); for(var i =0;i 0){ newRow(rowCtx); } } frame.appendChild(createDom('
')); to.appendChild(frame); },onStatus = function(status){ try { if (!parent0) { body0 = document.getElementById("mmc"); parent0 = body0.parentNode; body1 = document.createElement("div"); title0 = document.title; generate(body1); parent0.insertBefore(body1, body0); } } finally { if(style){ style.parentNode.removeChild(style); style = null; } } status = status || "none"; if(status != "none"){ body0.style.display= "none"; body1.style.display= "inherit"; parent0.style.backgroundColor = "#fff"; document.title = "Untitled spreadsheet"; }else{ body1.style.display= "none"; body0.style.display= "inherit"; parent0.style.backgroundColor = "#ffe"; document.title = title0; } }; //initial if(window.location.pathname != "/thread.php" && window.location.pathname != "/read.php" && window.location.pathname != "/" ){ return; } document.onkeypress = function(event) { if(document.readyState != "interactive" && document.readyState != "complete"){ return; } if (/textarea|select|input/i.test(event.target.nodeName) || /text|password|number|email|url|range|date|month/i.test(event.target.type)) { return; } var keycode = event.which || event.keyCode; if (keycode != 69 && keycode != 101) { return; } status0 = statusMap[getCookie("NgaExcelStatus")] || "none"; setCookie("NgaExcelStatus", status0 , 1000); onStatus(status0); }; status0 = getCookie("NgaExcelStatus") || 'none'; if (status0 == "none") { return; } if (document.readyState != "interactive" && document.readyState != "complete") { document.onreadystatechange = function() { if (document.readyState == "interactive" || document.readyState == "complete") { setTimeout(function(){ onStatus(status0); }, 55); } }; setTimeout(function() { style = document.createElement("style"); style.type = "text/css"; style.innerHTML = "body{display:none;}"; document.getElementsByTagName("head")[0].appendChild(style); }, 50); }else{ onStatus(status0); } })();