User:A2569875-sandbox/MyPopups

维基百科,自由的百科全书

錯誤:小工具安裝不完全,請參考User:A2569875-sandbox/MyPopups.js/doc#安裝重新安裝








Navigation popups ver.A2569875
WP:POP的模組
描述User:A2569875宇帆)版本WP:POP

本腳本為WP:POP的MOD,原始目的是希望其能支援跨語言連結預覽

緣起[编辑]

一開始僅是想試用WP:POP,但用了之後發現其他語言版本維基、維基數據等連結皆無法預覽,覺得不方便。起初想直接更改設定,但找不到可以改的地方,經詢問後發現不支援。 後來想直接寫WP:POP的插件,但接著發現,其產生連結的站點資訊是寫死的,在腳本載入時會直接填入本地網址,因此只能寫模組(Mod、Modification,程式修改)。

起初無法成功載入跨語言內容,後來依靠Using mediawiki.ForeignApi完成資料傳遞。但若要跨到維基媒體基金會姊妹計畫外面的話,其mediawiki.ForeignApi Token(下簡稱跨站通行證)不被維基媒體基金會姊妹計畫承認,例如萌娘百科的跨站通行證傳回中文維基時不被承認,因此CORS標頭被瀏覽器認為無效,這時只要安裝Allow-Control-Allow-Origin瀏覽器插件即可解決。

後來一時興起添加了些自己想用的其他功能。

安裝[编辑]

需要Mediawiki版本≥1.29
Mediawiki 1.31-alpha 测试通过
1. 將下列程式碼加入你的global.js頁面。
mw.loader.load('//zh.100ke.info/w/index.php?title=User:A2569875-sandbox/MyPopupsSetting_zh-hant.js&action=raw&ctype=text/javascript');
mw.loader.load('//zh.100ke.info/w/index.php?title=User:A2569875-sandbox/MyPopups.css&action=raw&ctype=text/css','text/css');
2. 關閉原本已啟用的WP:POP小工具,否則會發生衝突。
3. 部分瀏覽器需要安裝Allow-Control-Allow-Origin插件才能跨到非維基媒體姊妹計畫站。google瀏覽器版本火狐瀏覽器版本

若不要全域啟用則加到本地的common.jscommon.css

支援的頁面[编辑]

特殊頁面:
Special:ContributionsSpecial:EmailUserSpecial:WhatLinksHereSpecial:DiffSpecial:MyPageSpecial:LogSpecial:PermanentLink

回報Bug及建議[编辑]

功能[编辑]

功能 示範 說明
跨語言連結預覽 可以支援跨語言連結、其他維基姊妹計畫的預覽,
[[:ja:ウィキペディア]]
維基數據支援 可以顯示維基數據項目的摘要和部分的屬性代碼
跨站預覽 可以支援部分維基媒體基金會姊妹計畫之MediaWiki網站的預覽,
如萌娘百科、Gamepedia

(部分瀏覽器可能需要Allow-Control-Allow-Origin插件)

紅色連結預覽 若一個紅色連結是被刪除的頁面,則會列出該頁的日誌。
簡易程式碼上色預覽 將常見的程式語言關鍵字上色
Flow預覽 簡單列出Flow話題標題

參見[编辑]

User:A2569875-sandbox/MyPopups.js://
var pg = {
	re: {},               // regexps
	ns: {},               // namespaces
	string: {},           // translatable strings
	user: {},             // current user info
	wiki: {},             // local site info
	misc: {},             // YUCK PHOOEY
	option: {},           // options, see newOption etc
	optionDefault: {},    // default option values
	flag: {},             // misc flags
	cache: {},            // page and image cache
	structures: {},       // navlink structures
	timer: {},            // all sorts of timers (too damn many)
	counter: {},          // .. and all sorts of counters
	current: {},          // state info
	fn: {},               // functions
	apiToken: {},
	endoflist: null
};
/* Bail if the gadget/script is being loaded twice */
if( window.pg ) {
	return;
}
/* Export to global context */
window.pg = pg;

/// Local Variables: ///
/// mode:c ///
/// End: ///
// ENDFILE: main.js
// STARTFILE: actions.js
function setupTooltips(container, remove, force, popData) {
	log('setupTooltips, container='+container+', remove='+remove);
	if (!container) {
//<NOLITE>
		// the main initial call
		if (getValueOf('popupOnEditSelection') && document && document.editform && document.editform.wpTextbox1) {
			document.editform.wpTextbox1.onmouseup=doSelectionPopup;
		}
//</NOLITE>
		// article/content is a structure-dependent thing
		container = defaultPopupsContainer();
	}

	if (!remove && !force && container.ranSetupTooltipsAlready) { return; }
	container.ranSetupTooltipsAlready = !remove;

	var anchors;
	anchors=container.getElementsByTagName('A');
	setupTooltipsLoop(anchors, 0, 250, 100, remove, popData);
}

function defaultPopupsContainer() {
	if (getValueOf('popupOnlyArticleLinks')) {
		return document.getElementById('mw_content') || 
			document.getElementById('content') ||
			document.getElementById('article') || document;
	}
	return  document;
}

function setupTooltipsLoop(anchors,begin,howmany,sleep, remove, popData) {
	log(simplePrintf('setupTooltipsLoop(%s,%s,%s,%s,%s)', arguments));
	var finish=begin+howmany;
	var loopend = Math.min(finish, anchors.length);
	var j=loopend - begin;
	log ('setupTooltips: anchors.length=' + anchors.length + ', begin=' + begin +
		 ', howmany=' + howmany + ', loopend=' + loopend + ', remove=' + remove);
	var doTooltip= remove ? removeTooltip : addTooltip;
	// try a faster (?) loop construct
	if (j > 0) {
		do {
			var a=anchors[loopend - j];
			if (typeof a==='undefined' || !a || !a.href) {
				log('got null anchor at index ' + loopend - j);
				continue;
			}
			doTooltip(a, popData);
		} while (--j);
	}
	if (finish < anchors.length) {
		setTimeout(function() {
				setupTooltipsLoop(anchors,finish,howmany,sleep,remove,popData);},
			sleep);
	} else {
		if ( !remove && ! getValueOf('popupTocLinks')) { rmTocTooltips(); }
		pg.flag.finishedLoading=true;
	}
}

// eliminate popups from the TOC
// This also kills any onclick stuff that used to be going on in the toc
function rmTocTooltips() {
	var toc=document.getElementById('toc');
	if (toc) {
		var tocLinks=toc.getElementsByTagName('A');
		var tocLen = tocLinks.length;
		for (var j=0; j<tocLen; ++j) {
			removeTooltip(tocLinks[j], true);
		}
	}
}

function addTooltip(a, popData) {
	if ( !isPopupLink(a) ) { return; }
	a.onmouseover=mouseOverWikiLink;
	a.onmouseout= mouseOutWikiLink;
	a.onmousedown = killPopup;
	a.hasPopup = true;
	a.popData = popData;
}

function removeTooltip(a) {
	if ( !a.hasPopup ) { return; }
	a.onmouseover = null;
	a.onmouseout = null;
	if (a.originalTitle) { a.title = a.originalTitle; }
	a.hasPopup=false;
}

function removeTitle(a) {
	if (!a.originalTitle) {
		a.originalTitle=a.title;
	}
		a.title='';
}

function restoreTitle(a) {
	if ( a.title || !a.originalTitle ) { return; }
	a.title = a.originalTitle;
}

function registerHooks(np) {
	var popupMaxWidth=getValueOf('popupMaxWidth');

	if (typeof popupMaxWidth === 'number') {
		var setMaxWidth = function () {
			np.mainDiv.style.maxWidth = popupMaxWidth + 'px';
			np.maxWidth = popupMaxWidth;
		};
		np.addHook(setMaxWidth, 'unhide', 'before');
	}
//<NOLITE>
	np.addHook(addPopupShortcuts, 'unhide', 'after');
	np.addHook(rmPopupShortcuts, 'hide', 'before');
//</NOLITE>
}

function removeModifierKeyHandler(a) {
	//remove listeners for modifier key if any that were added in mouseOverWikiLink
	document.removeEventListener('keydown', a.modifierKeyHandler, false);
	document.removeEventListener('keyup', a.modifierKeyHandler, false);
}

function mouseOverWikiLink(evt) {
	if (!evt && window.event) {evt=window.event;}
	
	// if the modifier is needed, listen for it, 
	// we will remove the listener when we mouseout of this link or kill popup.
	if (getValueOf('popupModifier')) {
		// if popupModifierAction = enable, we should popup when the modifier is pressed
		// if popupModifierAction = disable, we should popup unless the modifier is pressed 
    	var action = getValueOf('popupModifierAction');
    	var key = action=='disable' ? 'keyup' : 'keydown';
    	var a = this;
    	a.modifierKeyHandler = function(evt) {
			mouseOverWikiLink2(a, evt);
		};
    	document.addEventListener(key, a.modifierKeyHandler, false);
	}
	return mouseOverWikiLink2(this, evt);
}

/**
 * Gets the references list item that the provided footnote link targets. This
 * is typically a li element within the ol.references element inside the reflist.
 * @param {Element} a - A footnote link.
 * @returns {Element|boolean} The targeted element, or false if one can't be found. 
 */
function footnoteTarget(a) {
	var aTitle=Title.fromAnchor(a);
	// We want ".3A" rather than "%3A" or "?" here, so use the anchor property directly
	var anch = aTitle.anchor;
	if ( ! /^(cite_note-|_note-|endnote)/.test(anch) ) { return false; }

	var lTitle=Title.fromURL(location.href);
	if ( lTitle.toString(true) !== aTitle.toString(true) ) { return false; }

	var el=document.getElementById(anch);
	while ( el && typeof el.nodeName === 'string') {
		var nt = el.nodeName.toLowerCase();
		if ( nt === 'li' ) { return el; }
		else if ( nt === 'body' ) { return false; }
		else if ( el.parentNode ) { el=el.parentNode; }
		else { return false; }
	}
	return false;
}

function footnotePreview(x, navpop) {
	setPopupHTML('<hr />' + x.innerHTML, 'popupPreview', navpop.idNumber);
//
更多...
User:A2569875-sandbox/MyPopups.css:/*
 */
ins.popupDiff {
  background: #afe;
}

del.popupDiff {
  background: #ffe6e6;
}

#selectionPreview {
  border: 2px solid #ddd;
  background-color: #eef;
  padding: 6px;
}

.navpopup {
  border: 1px solid #bbb;
  background-color: #fff;
  padding: 10px;
  padding-bottom: 5px;
  font-size: 11px;
  box-shadow: 0 3px 8px rgba( 50, 50, 50, 0.35 );
  word-wrap: break-word;
}

.navpopup hr {
  color: #aaa !important;
  background-color: #aaa !important;
}

/* Configure Drag bar color */
.popupDrag {
  background-color: #ffbe20;
  height: 5px;
  margin-top: -5px;
  margin-bottom: 5px;
}

.popupDragHandle {
  cursor: move;
  position: relative;
}
/*