本館粉絲專頁

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

分享此網頁到Facebook
分享此網頁到Plurk
分享此網頁到百度搜藏
分享此網頁到Twitter
分享此網頁到Del.icio.us
台灣棒球維基館
跳轉到: 導覽搜尋
第18行: 第18行:
 
console.log(PVC);
 
console.log(PVC);
 
       if (PVC.length > 0) {
 
       if (PVC.length > 0) {
         A[i].addEventListener("click", function(event) {
+
         A[i].addEventListener("mousedown", function(event) {
 
           setTimeout('__dgpk_preview()', 100);
 
           setTimeout('__dgpk_preview()', 100);
 
         }, false);
 
         }, false);

2018年7月27日 (五) 12:32的修訂版本

importScript('User:Digipunk/FC/func.js');
 
window.addEventListener("load", function(event) {
  DGPK_ONLOAD_ACTIONS();
}, false);
 
//var DGPK_timer = null;
var WE = document.getElementsByClassName('wikiEditor-ui-tabs');
var PV = document.getElementsByClassName('wikiEditor-ui-view-preview');
var PVC = null; // preview content
console.log(WE);
console.log(PV);
if (WE.length > 0 && PV.length > 0) {
  var A = WE[0].getElementsByTagNames('A');
  for (var i = 0, ii = A.length; i < ii; i++) {
    if (A[i].innerHTML == '預覽') {
      PVC = PV[0].getElementsByClassName('wikiEditor-preview-contents');
console.log(PVC);
      if (PVC.length > 0) {
        A[i].addEventListener("mousedown", function(event) {
          setTimeout('__dgpk_preview()', 100);
        }, false);
      }
      break;
    }
  }
}
 
function __dgpk_preview() {
  if (PVC[0].innerHTML == '') {
    setTimeout('__dgpk_preview()', 200);
  } else {
    DGPK_ONLOAD_ACTIONS();
  }
}
 
function DGPK_ONLOAD_ACTIONS() {{{
  try { DGPKJS_CSS_JS(); } catch (e) { console.log(e); }
  try { DGPKJS_FC();     } catch (e) { console.log(e); }
}}}
 
//--------------------------------------------------
// 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 i = JS.length - 1; i >= 0; i--) {
    eval(JS[i].innerText);
    JS[i].parentNode.removeChild(JS[i]);
  }
}
 
//--------------------------------------------------
// 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, '.');
  }
}