NGA Excel

原userscripts-mirror上风昔大大的NGA Excel,简单更新了部分代码使之可用。

  1. // ==UserScript==
  2. // @name NGA Excel
  3. // @author 风昔
  4. // @description 原userscripts-mirror上风昔大大的NGA Excel,简单更新了部分代码使之可用。
  5. // @version 1.1.3
  6. // @match http://bbs.ngacn.cc/*
  7. // @include http://bbs.ngacn.cc/*
  8. // @match http://nga.178.com/*
  9. // @include http://nga.178.com/*
  10. // @match http://bbs.nga.cn/*
  11. // @include http://bbs.nga.cn/*
  12. // @run-at document-start
  13. // @namespace https://gf.qytechs.cn/users/179759
  14. // ==/UserScript==
  15.  
  16.  
  17. (function(){
  18.  
  19. 'use strict';
  20. var body0, body1, parent0, title0, status0, style,
  21.  
  22. statusMap ={
  23. none : 'normal',
  24. normal : 'none',
  25. clean : 'none'
  26. }, createDom = function(html) {
  27. var tmp = document.createElement("div");
  28. tmp.innerHTML = html;
  29. return tmp.childNodes[0];
  30. }, setCookie = function(c_name,value, expire){
  31. var expiredays = expire || 1;
  32. var exdate = new Date();
  33. exdate.setDate(exdate.getDate() + expiredays);
  34. document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
  35. }, getCookie = function(c_name) {
  36. var cookies = document.cookie.split(';');
  37. var cookie = '';
  38. for ( var i = 0; i < cookies.length; i++) {
  39. cookie = cookies[i].split('=');
  40. if (cookie[0].replace(/^\s+|\s+$/g, '') == c_name) {
  41. return (cookie.length <= 1) ? "" : unescape(cookie[1].replace(
  42. /^\s+|\s+$/g, ''));
  43. }
  44. }
  45. return "";
  46. }, removeClass = function(dom){
  47. dom.className = "";
  48. for(var i =0; i< dom.children.length;i++){
  49. removeClass(dom.children[i]);
  50. }
  51. return dom;
  52. },generate = function(to) {
  53. var rowCount = -1,
  54. frame = createDom('<div><div style="position: fixed; top: 0; width:100%; background: url(http://pic3.178.com/2126/21268720/month_1310/77cf4384624dcdc285a52ced7f9d6a2e.PNG) left no-repeat; height: 142px;"></div></div>'),
  55. threadsTable = createDom('<table style="margin-top: 142px; margin-bottom: 42px; background-color : #fff; font-size: 13px;table-layout: fixed;border-collapse: separate;border-style: none;border-spacing: 0;border-color: gray;width: 100%;"></table>'),
  56. rootNav = createDom('<a class="uitxt1" href="/">NGA</a>'),
  57. newRow = function(ctx){
  58. var rowDom =document.createElement("tr"),
  59. rowHTML = '<td width="35px;" style="vertical-align:top; padding: 5px; border: 1px #ccc solid; border-width: 0 1px 1px 0; text-align: center;">' + ( rowCount< 1 ? '' : rowCount ) + '</td>';
  60.  
  61. rowCount++;
  62. for(var i = 0; i < ctx.length; i++){
  63. rowHTML += '<td width="330px;" style="vertical-align:top; padding: 5px; overflow: hidden; border: 1px #ccc solid; border-width: 0 1px 1px 0;"></td>';
  64. }
  65. rowDom.innerHTML = rowHTML;
  66. rowDom.children[rowDom.children.length-1].removeAttribute("width");
  67. for(var i = 0; i < ctx.length; i++){
  68. if(typeof ctx[i] == "string"){
  69. rowDom.children[i+1].textContent = rowDom.children[i+1].innerText = ctx[i];
  70. }else{
  71. rowDom.children[i+1].appendChild(ctx[i].cloneNode(true));
  72. }
  73. }
  74. threadsTable.appendChild(rowDom);
  75. },getAnchor = function(tb, type){
  76. if(tb instanceof Array){
  77. tb = tb[0];
  78. }
  79. var args, scripts = tb.getElementsByTagName("script"),
  80. anchor = createDom("<a style='float:right;' href=''>REPLY</a>");
  81. try{
  82. for(var i = 0; i < scripts.length; i++){
  83. if(/commonui\.postArg\.proc/.test(scripts[i].innerHTML)){
  84. args = scripts[i].innerHTML.replace(/^[^(]*\(|\s*/g,"").split(",");
  85. break;
  86. }
  87. }
  88. if(type == 1){
  89. anchor.setAttribute("href","/post.php?action=reply&_newui&fid="+ args[8] +"&tid=" + args[9]);
  90. }else{
  91. anchor.setAttribute("href","/post.php?action=quote&_newui&fid="+ args[8] +"&tid=" + args[9] + "&pid=" + args[10] + "&article="+ args[0]);
  92. }
  93. }catch(e){
  94. return tb.nextElementSibling ? getAnchor(tb.nextElementSibling, type) : anchor;
  95. }
  96. return anchor;
  97. };
  98. frame.appendChild(threadsTable);
  99. if(window.location.pathname == "/thread.php"){
  100. var dom=document.getElementById("topicrows"),
  101. nav0 = document.getElementById("m_pbtntop").getElementsByTagName("a"),
  102. nav1 = document.createElement("div"),
  103. topics = dom.children[1].children, ctx;
  104. for(var i = 0; i< nav0.length;i++){
  105. if(!isNaN(Number(nav0[i].textContent))){
  106. nav1.appendChild(nav0[i].cloneNode(true));
  107. }
  108. }
  109. newRow(["", "", rootNav, nav1]);
  110. newRow(["REPLIES","STARTER", "LAST POST", ""]);
  111. for ( var i = 0; i < dom.children.length; i+=2) {
  112. ctx= [];
  113. var str=dom.children[i].children[0].children[1].children[1].textContent;
  114. var item=dom.children[i].children[0].children[1].children[0];
  115. if(str.charAt(str.length - 1)!="•" ){item=dom.children[i].children[0].children[1].children[1];}
  116. ctx.push(item);
  117. ctx.push(dom.children[i].children[0].children[2].children[0].textContent);
  118. /*ctx.push(topics[i].children[0].textContent);
  119. ctx.push(topics[i].children[2].children[0].textContent);
  120. ctx.push(topics[i].children[3].children[1].textContent);
  121. var threadCtx = topics[i].children[1].children,
  122. threadNew = createDom('<div></div>');
  123. for(var j= 0; j < threadCtx.length; j++){
  124. threadNew.appendChild(removeClass(threadCtx[j].cloneNode(true)));
  125. }
  126. ctx.push(threadNew);*/
  127. ctx.push(dom.children[i].children[0].children[3].children[0].textContent);
  128. ctx.push("");
  129. newRow(ctx);
  130. }
  131.  
  132. newRow(["", "", rootNav, nav1]);
  133. } else if(window.location.pathname == "/read.php"){
  134. var nav0 = [],
  135. nav1 = document.createElement("div"),
  136. navAnchors0 = document.getElementById("m_pbtntop").getElementsByTagName("a"),
  137. navAnchors1 = document.getElementById("m_nav").getElementsByTagName("a"),
  138. postTables = (function() {
  139. var tables = document.getElementsByTagName("table"), res = [], i = 0;
  140. for (; i < tables.length; i++) {
  141. if (tables[i].className == "forumbox postbox") {
  142. res.push(tables[i]);
  143. }
  144. }
  145. return res;
  146. })(),
  147. startIndex = Number(postTables[0].getElementsByTagName("tr")[0].getAttribute("id").substr(10));
  148. for(var i = 1; i< navAnchors1.length;i++){
  149. if (navAnchors1[i].className == "nav_link") {
  150. navAnchors1[i].className ="uitxt1";
  151. nav0.push(navAnchors1[i].cloneNode(true));
  152. }
  153. }
  154. nav1.appendChild(nav0[nav0.length-1]);
  155. for(var i = 0; i< navAnchors0.length;i++){
  156. if(!isNaN(Number(navAnchors0[i].textContent))){
  157. nav1.appendChild(navAnchors0[i].cloneNode(true));
  158. }
  159. }
  160. nav1.appendChild(getAnchor(postTables, 1));
  161. newRow([rootNav,nav0[0],nav1]);
  162. newRow(["AUTHOR","TIME", "CONTENT"]);
  163. for ( var i = startIndex; i < postTables.length + startIndex; i++) {
  164. try{
  165. var ctx = [];
  166. ctx.push(document.getElementById("postauthor" + i).textContent);
  167. ctx.push(document.getElementById("postdate" + i).textContent);
  168. ctx.push(document.getElementById("postcontent" + i).cloneNode(true));
  169. ctx[2].appendChild(getAnchor(postTables[i-startIndex]));
  170. newRow(ctx);
  171. }catch(e){
  172. }
  173. }
  174. newRow([rootNav,nav0[0],nav1]);
  175. } else{
  176. rowCount = 1;
  177. var rowCtx = [],hrefs = document.getElementsByTagName("a");
  178. for(var i =0;i<hrefs.length;i++){
  179. if(hrefs[i].getAttribute("href").substr(0,7) == "/thread"){
  180. rowCtx.push(hrefs[i].cloneNode(true));
  181. }
  182. if(rowCtx.length == 5){
  183. newRow(rowCtx);
  184. rowCtx=[];
  185. }
  186. }
  187. if(rowCtx.length > 0){
  188. newRow(rowCtx);
  189. }
  190. }
  191. frame.appendChild(createDom('<div style="position: fixed; bottom: 0; width:100%; background: url(http://pic3.178.com/2126/21268720/month_1310/8f0711665fac9e200f742934cf92069b.PNG) left no-repeat; height: 42px;"></div>'));
  192. to.appendChild(frame);
  193. },onStatus = function(status){
  194.  
  195. try {
  196. if (!parent0) {
  197. body0 = document.getElementById("mmc");
  198. parent0 = body0.parentNode;
  199. body1 = document.createElement("div");
  200. title0 = document.title;
  201. generate(body1);
  202.  
  203. parent0.insertBefore(body1, body0);
  204.  
  205. }
  206. } finally {
  207. if(style){
  208. style.parentNode.removeChild(style);
  209. style = null;
  210. }
  211. }
  212. status = status || "none";
  213. if(status != "none"){
  214. body0.style.display= "none";
  215. body1.style.display= "inherit";
  216. parent0.style.backgroundColor = "#fff";
  217. document.title = "Untitled spreadsheet";
  218. }else{
  219. body1.style.display= "none";
  220. body0.style.display= "inherit";
  221. parent0.style.backgroundColor = "#ffe";
  222. document.title = title0;
  223. }
  224.  
  225. };
  226.  
  227. //initial
  228. if(window.location.pathname != "/thread.php"
  229. && window.location.pathname != "/read.php"
  230. && window.location.pathname != "/" ){
  231. return;
  232. }
  233.  
  234. document.onkeypress = function(event) {
  235. if(document.readyState != "interactive"
  236. && document.readyState != "complete"){
  237. return;
  238. }
  239. if (/textarea|select|input/i.test(event.target.nodeName)
  240. || /text|password|number|email|url|range|date|month/i.test(event.target.type)) {
  241. return;
  242. }
  243. var keycode = event.which || event.keyCode;
  244. if (keycode != 69 && keycode != 101) {
  245. return;
  246. }
  247. status0 = statusMap[getCookie("NgaExcelStatus")] || "none";
  248. setCookie("NgaExcelStatus", status0 , 1000);
  249. onStatus(status0);
  250. };
  251.  
  252. status0 = getCookie("NgaExcelStatus") || 'none';
  253. if (status0 == "none") {
  254. return;
  255. }
  256.  
  257. if (document.readyState != "interactive"
  258. && document.readyState != "complete") {
  259.  
  260. document.onreadystatechange = function() {
  261. if (document.readyState == "interactive"
  262. || document.readyState == "complete") {
  263. setTimeout(function(){
  264. onStatus(status0);
  265. }, 55);
  266. }
  267. };
  268. setTimeout(function() {
  269. style = document.createElement("style");
  270. style.type = "text/css";
  271. style.innerHTML = "body{display:none;}";
  272.  
  273. document.getElementsByTagName("head")[0].appendChild(style);
  274. }, 50);
  275. }else{
  276. onStatus(status0);
  277. }
  278. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址