|
|
本館粉絲專頁 |
|
|
使用者:Digipunk/mw-common.js:修訂版本之間的差異
台灣棒球維基館
小 |
小 |
||
| 第112行: | 第112行: | ||
}); | }); | ||
if (TBL[j].tBodies[k].children[x].children.length > 0) { | if (TBL[j].tBodies[k].children[x].children.length > 0) { | ||
| − | TBL[j].tBodies[k].children[x].children[0].className += ' fixed-ord'; | + | //TBL[j].tBodies[k].children[x].children[0].className += ' fixed-ord'; |
| + | // 乾脆這裡一次解決,fixed-ord 留給外部彈性使用 | ||
| + | TBL[j].tBodies[k].children[x].children[0].innerHTML = '<S>' + ('00' + x).substr(-3) + '</S>' + TBL[j].tBodies[k].children[x].children[0].innerHTML; | ||
} | } | ||
} | } | ||
2018年9月11日 (二) 20:07的修訂版本
// importScript() 為舊版寫法,新版需改用 mw.loader.load() 或直接在 LocalSettings.php 裡建立 importScript() importScript('User:Digipunk/FC/func.js'); importScript('User:Digipunk/SC/func.js'); // 處理新版 MW 在 </DIV><BR> 後面強行加入 <P><BR></P> if (mw.config.get('wgVersion').localeCompare('1.3') >= 0) { document.body.innerHTML = document.body.innerHTML.replace(/<\/div>([\r\n]*)<p><br[ \/]*>\s*<\/p>/ig, '</div>$1<br />'); } window.addEventListener("load", function(event) { DGPK_ONLOAD_ACTIONS(); DGPK_CHECK_PREVIEW(); }, false); function DGPK_ONLOAD_ACTIONS() {{{ try { DGPKJS_CSS_JS(); } catch (e) { console.log(e); } try { DGPKJS_FC(); } catch (e) { console.log(e); } try { DGPKJS_SC(); } catch (e) { console.log(e); } try { DGPKJS_STATS(); } catch (e) { console.log(e); } try { DGPKJS_MOVER(); } catch (e) { console.log(e); } // TR.mover highlight try { DGPKJS_SORTALBE(); } catch (e) { console.log(e); } // TABLE.sortable TD.fixed-ord sno }}} //-------------------------------------------------- // deal with the built-in AJAX preview //-------------------------------------------------- function DGPK_CHECK_PREVIEW() {{{ var WE = document.getElementsByClassName('wikiEditor-ui-tabs'); var PV = document.getElementsByClassName('wikiEditor-ui-view-preview'); if (WE.length > 0 && PV.length > 0) { var A = WE[0].getElementsByTagName('A'); for (var i = 0, ii = A.length; i < ii; i++) { if (A[i].innerHTML == '預覽') { var PVC = PV[0].getElementsByClassName('wikiEditor-preview-contents'); // preview content if (PVC.length > 0) { A[i].addEventListener("mousedown", function(event) { setTimeout(function() { __dgpk_preview(PVC[0], 0); }, 200); }, false); } break; } } } }}} function __dgpk_preview(pvc, counter) {{{ if (pvc.innerHTML == '' && counter < 50) { setTimeout(function() { __dgpk_preview(pvc, ++counter); }, 100); } else { DGPK_ONLOAD_ACTIONS(); } }}} //-------------------------------------------------- // insert CSS rules to individual page // and eval script snippet //-------------------------------------------------- function DGPKJS_CSS_JS() {{{ var CSS = document.getElementsByClassName('DGPK-css'); var n = CSS.length; if (n > 0) { var style = (function() { var el = document.createElement('style'); el.appendChild(document.createTextNode('')); // WebKit hack el.type = 'text/css'; el.rel = 'stylesheet'; el.media = 'screen'; // el.id = id; document.head.appendChild(el); return el.sheet; })(); for (var i = n - 1; i >= 0; i--) { //var rules = CSS[i].innerHTML.replace(/<\/?[^>]+>/g, '').split("\n"); var rules = CSS[i].innerText.split("}"); for (var j = 0, jj = rules.length; j < jj; j++) { if (rules[j].trim() == '') continue; style.insertRule(rules[j] + '}'); } CSS[i].parentNode.removeChild(CSS[i]); } } var JS = document.getElementsByClassName('DGPK-js'); for (var zzi = JS.length - 1; zzi >= 0; zzi--) { (function () { eval(JS[zzi].innerText); }()); // 丟到函式裡執行,避免 eval 裡的變數影響這裡 JS[zzi].parentNode.removeChild(JS[zzi]); } }}} function DGPKJS_STATS() {{{ var CLS = ['TBL-DATA-B', 'TBL-DATA-P']; for (var i = 0; i < 2; i++) { var TBL = document.getElementsByClassName(CLS[i]); for (var j = 0, jj = TBL.length; j < jj; j++) { for (var k = 0, kk = TBL[j].tBodies.length; k < kk; k++) { for (var x = 0, xx = TBL[j].tBodies[k].children.length; x < xx; x++) { if (TBL[j].tBodies[k].children[x].tagName == 'TR' && ['title', 'column', 'sortbottom'].indexOf(TBL[j].tBodies[k].children[x].className) < 0) { TBL[j].tBodies[k].children[x].className += ' mover'; TBL[j].tBodies[k].children[x].innerHTML = TBL[j].tBodies[k].children[x].innerHTML.replace(/>(\s*)(\d+)\//g, function(m, a, b) { return '>' + a + '<S>' + ('00' + b).substr(-3) + '</S>' + b + '/'; }); if (TBL[j].tBodies[k].children[x].children.length > 0) { //TBL[j].tBodies[k].children[x].children[0].className += ' fixed-ord'; // 乾脆這裡一次解決,fixed-ord 留給外部彈性使用 TBL[j].tBodies[k].children[x].children[0].innerHTML = '<S>' + ('00' + x).substr(-3) + '</S>' + TBL[j].tBodies[k].children[x].children[0].innerHTML; } } } } } } }}} function DGPKJS_SORTALBE() {{{ var SORTABLE = document.getElementsByClassName('sortable'); for (var i = 0, ii = SORTABLE.length; i < ii; i++) { var elmts = SORTABLE[i].getElementsByClassName('fixed-ord'); for (var j = 0, jj = elmts.length; j < jj; j++) { elmts[j].innerHTML = '<SPAN STYLE="display:none">' + ('00' + j).substr(-3) + '</SPAN>' + elmts[j].innerHTML; } } }}} function DGPKJS_MOVER() {{{ var TR = document.getElementsByClassName('mover'); for (var i = 0, ii = TR.length; i < ii; i++) { TR[i].addEventListener("mouseover", function(event) { this.className += ' mev-over'; }, false); TR[i].addEventListener("mouseout", function(event) { this.className = this.className.replace(/ mev-over/g, ''); }, false); } var TR = document.getElementsByClassName('mover-f'); for (var i = 0, ii = TR.length; i < ii; i++) { TR[i].addEventListener("mouseover", function(event) { this.className += ' mev-over-f'; }, false); TR[i].addEventListener("mouseout", function(event) { this.className = this.className.replace(/ mev-over-f/g, ''); }, false); } }}} //-------------------------------------------------- // Utilities //-------------------------------------------------- // normalize uri to conform to wiki format function dgpk_wikilink(str) {{{ var pos = str.indexOf('#'); if (pos < 0) { return encodeURI(str); } else { return encodeURI(str.substr(0, pos)) + '#' + encodeURIComponent(str.substr(pos + 1)).replace(/%/g, '.'); } }}}