用户:A2569875-sandbox/MyPopups
错误:小工具安装不完全,请参考User:A2569875-sandbox/MyPopups.js/doc#安装重新安装
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.wikipedia.org/w/index.php?title=User:A2569875-sandbox/MyPopupsSetting_zh-hant.js&action=raw&ctype=text/javascript');
mw.loader.load('//zh.wikipedia.org/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.js、common.css。
支援的页面
- 特殊页面:
回报Bug及建议
- User talk:A2569875-sandbox/MyPopups 请在讨论页留言(不要在说明文档或js档的讨论页留言)
功能
参见
- 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; } /*