本館粉絲專頁

使用者:Digipunk/mw-common.js:修訂版本之間的差異

分享此網頁到Facebook
分享此網頁到Plurk
分享此網頁到百度搜藏
分享此網頁到Twitter
分享此網頁到Del.icio.us
台灣棒球維基館
跳轉到: 導覽搜尋
第1行: 第1行:
 +
// importScript() 為舊版寫法,新版需改用 mw.loader.load() 或直接在 LocalSettings.php 裡建立 importScript()
 
importScript('User:Digipunk/FC/func.js');
 
importScript('User:Digipunk/FC/func.js');
 
importScript('User:Digipunk/SC/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) {
 
window.addEventListener("load", function(event) {
第8行: 第14行:
  
 
function DGPK_ONLOAD_ACTIONS() {{{
 
function DGPK_ONLOAD_ACTIONS() {{{
   try { DGPKJS_CSS_JS(); } catch (e) { console.log(e); }
+
   try { DGPKJS_FC();       } catch (e) { console.log(e); }
   try { DGPKJS_FC();     } catch (e) { console.log(e); }
+
   try { DGPKJS_SC();       } catch (e) { console.log(e); }
   try { DGPKJS_SC();     } catch (e) { console.log(e); }
+
 
 +
   try { DGPKJS_SORTALBE(); } catch (e) { console.log(e); }
 +
  try { DGPKJS_CSS_JS();  } catch (e) { console.log(e); }
 
}}}
 
}}}
  
第17行: 第25行:
 
// deal with the built-in AJAX preview
 
// deal with the built-in AJAX preview
 
//--------------------------------------------------
 
//--------------------------------------------------
function DGPK_CHECK_PREVIEW() {
+
function DGPK_CHECK_PREVIEW() {{{
 
   var WE = document.getElementsByClassName('wikiEditor-ui-tabs');
 
   var WE = document.getElementsByClassName('wikiEditor-ui-tabs');
 
   var PV = document.getElementsByClassName('wikiEditor-ui-view-preview');
 
   var PV = document.getElementsByClassName('wikiEditor-ui-view-preview');
第38行: 第46行:
 
     }
 
     }
 
   }
 
   }
}
+
}}}
  
function __dgpk_preview(pvc, counter) {
+
function __dgpk_preview(pvc, counter) {{{
 
   if (pvc.innerHTML == '' && counter < 50) {
 
   if (pvc.innerHTML == '' && counter < 50) {
 
     setTimeout(function() {
 
     setTimeout(function() {
第48行: 第56行:
 
     DGPK_ONLOAD_ACTIONS();
 
     DGPK_ONLOAD_ACTIONS();
 
   }
 
   }
}
+
}}}
  
 
//--------------------------------------------------
 
//--------------------------------------------------
第54行: 第62行:
 
// and eval script snippet
 
// and eval script snippet
 
//--------------------------------------------------
 
//--------------------------------------------------
function DGPKJS_CSS_JS() {
+
function DGPKJS_CSS_JS() {{{
 
   var CSS = document.getElementsByClassName('DGPK-css');
 
   var CSS = document.getElementsByClassName('DGPK-css');
 
   var n = CSS.length;
 
   var n = CSS.length;
第85行: 第93行:
 
     JS[zzi].parentNode.removeChild(JS[zzi]);
 
     JS[zzi].parentNode.removeChild(JS[zzi]);
 
   }
 
   }
}
+
}}}
 +
 
 +
function DGPKJS_SORTALBE() {{{
 +
  var SORTABLE = document.getElementsByClassName('DGPK-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;
 +
    }
 +
  }
 +
}}}
  
 
//--------------------------------------------------
 
//--------------------------------------------------
第91行: 第109行:
 
//--------------------------------------------------
 
//--------------------------------------------------
 
// normalize uri to conform to wiki format
 
// normalize uri to conform to wiki format
function dgpk_wikilink(str) {
+
function dgpk_wikilink(str) {{{
 
   var pos = str.indexOf('#');
 
   var pos = str.indexOf('#');
 
   if (pos < 0) {
 
   if (pos < 0) {
第98行: 第116行:
 
     return encodeURI(str.substr(0, pos)) + '#' + encodeURIComponent(str.substr(pos + 1)).replace(/%/g, '.');
 
     return encodeURI(str.substr(0, pos)) + '#' + encodeURIComponent(str.substr(pos + 1)).replace(/%/g, '.');
 
   }
 
   }
}
+
}}}

2018年9月11日 (二) 13:45的修訂版本

// 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_FC();       } catch (e) { console.log(e); }
  try { DGPKJS_SC();       } catch (e) { console.log(e); }
 
  try { DGPKJS_SORTALBE(); } catch (e) { console.log(e); }
  try { DGPKJS_CSS_JS();   } catch (e) { console.log(e); }
}}}
 
 
//--------------------------------------------------
// 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_SORTALBE() {{{
  var SORTABLE = document.getElementsByClassName('DGPK-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;
    }
  }
}}}
 
//--------------------------------------------------
// 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, '.');
  }
}}}