User:Bhsd/common.js

< User:Bhsd
Bhsd讨论 | 贡献2020年7月26日 (日) 00:44的版本

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
// <nowiki>
/*
  本工具會在「顯示預覽」按鈕增加選單,選單裏有各種地區字詞轉換的語言
  當按下「顯示預覽」後,便會以選單中所選的地區字詞來預覽
  這可以毋須在保存後再切換用字模式才能看到效果,直接用預覽便可檢視各種用字模式,從而減少bug的保存
*/

	$(function() {
		//偵測「顯示預覽」按鈕
		$('#wpPreview, input[name=wpTemplateSandboxPreview]').each( function(){
			var $this=$(this);
			
			//建立菜單
			var $listVariant=this.$listVariant=$('<select />')
			.attr("name", ("listVariant_"+$this.attr("name")) || ("listVariant_"+$this.attr("id")) )
			.attr("id"  , ("listVariant_"+$this.attr("id")) || ("listVariant_"+$this.attr("name")) )
			;
			
			//建立菜單選項
			(function addVarOpt(text, variant){
				$("<option />")
				.text(text)
				.each( function(){
					this.selected=this.defaultSelected=(mw.config.get('wgUserVariant')==(this.value=variant));
				})
				.appendTo($listVariant)
				;
				
				return addVarOpt;
			})
			("不转換", "zh")
			("简体", "zh-hans")
			("繁體", "zh-hant")
			("大陆简体", "zh-cn")
			("香港繁體", "zh-hk")
			("澳門繁體", "zh-mo")
			("马来西亚简体", "zh-my")
			("新加坡简体", "zh-sg")
			("臺灣繁體", "zh-tw")
			;
			
			//为了保障OOUI下button所包裹其span的功能,将button与其包裹的span作为整体去调整
			var $insertBlock=$this.parent("span");
			//安排位置
			$('<span />')
			.css({
				 "border"      : "1px dashed grey"
				,"white-space" : "nowrap"
				,"padding"     : "10px"
			})
			.text("以")
			.append($listVariant)
			.insertAfter($insertBlock)
			.append($insertBlock)
			;
			
			//修改預覽按鈕單擊動作
			$this.click( function(){
				//被按下時在表單傳送字串添加variant參數
				var listVariantValue=this.$listVariant.find("option:selected").get(0).value;
				
				mw.config.set('wgUserLanguage', listVariantValue);
				var $form=$this.parents("form");
				$form.attr(
					 "action"
					,$form
					 .attr("action")
					 .replace(/\&variant\=[^\&\?\#]*($|\&)/g, "$1")
					 .replace(/\?variant\=[^\&\?\#]*(?:$|\&)/, "?")
					 .replace(/\?/,"?variant="+listVariantValue+"&")
					 .replace(/\&$/, "")
				);
			});
			
		});
	});

// </nowiki>

$('div#p-tb div ul li#t-whatlinkshere').after('<li id="t-mybacklink"><a href="/zh?title=Special:链入页面/' + mw.config.get("wgPageName") + '&hidelinks=1&hideredirs=1&namespace=0" title="Special:链入页面">嵌入页面</a></li><li id="t-expandtemplates"><a href="/zh?title=Special:展开模板&wpRemoveComments=1&wpGenerateRawHtml=true&wpInput={{' + mw.config.get("wgPageName") + '}}" title="Special:展开模板">展开模板</a></li><li id="t-prefixindex"><a href="/zh?title=Special:前缀索引&prefix=' + mw.config.get("wgTitle") + '&namespace=' + mw.config.get("wgNamespaceNumber") + '" title="Special:前缀索引">子页面</a></li><li id="t-newestpages"><a href="/zh?title=Special:最新页面&namespace=10" title="Special:最新页面">新模板</a></li><li id="t-mychangeslinked"><a href="/zh?title=Special:链出更改&hidemyself=1&target=' + mw.config.get("wgPageName") + '" title="Special:链出更改">链出更改</a></li><li id="t-filter"><a href="/zh/Special:滥用过滤器" title="Special:滥用过滤器">滥用过滤器</a></li><li id="t-version"><a href="/zh/Special:版本" title="Special:版本">版本</a></li>');

/*
*名称:屏幕像素测距器
*作者:商火
*版本号:1.1
*功能描述:就是算两个点的像素差
*/
$('#footer').after('<div id="pxrulerpoint"></div><div id="pxruler_toggle" style="transition:.37s all ease-in-out;width:20px;padding:5px 0;background-color:#000;color:#fff;font-size:8px;text-align:center;position:fixed;left:0;top:100px;cursor:pointer;opacity:.6;" onclick="pxruler()">像<br/>素<br/>测<br/>距</div>');
var x1, y1, x2 = null, y2 = null, x3 = null, y3 = null;

//操作页面
function pxruler(){
	document.body.setAttribute("onmousedown", "setpoint1(event)");
	document.body.setAttribute("onmousemove", "selecting(event)");
	document.body.setAttribute("onmousewheel", "selecting(event)");
	document.getElementById('pxrulerpoint').innerHTML='<div id="pxrulertable" style="position:fixed; bottom:30px; left:10px; border:; padding:5px; background:#F6F6F6; opacity:.8;"><p id="point1xy">x1:-- y1:--</p><p id="point2xy">x2:-- y2:--</p><p id="deltaxy">Δx:-- Δy:--</p><hr/><p id="point3xy">x:-- y:--</p></div><div id="point1" style="position:absolute; top:; left:; width:8px; height:8px; background-color:#ee0000; border-radius:50%"></div><div id="point2" style="position:absolute; top:; left:; width:8px; height:8px; background-color:#66ccff; border-radius:50%"></div><div id="point3" style="position:absolute; top:; left:; width:8px;height:8px;background-color:#ee0000;border-radius:50%; opacity:.6"></div>';
	document.getElementById('pxruler_toggle').setAttribute("onclick", "exitpxruler()");
}
function exitpxruler(){
	document.getElementById('pxrulerpoint').innerHTML='';
	document.getElementById('pxruler_toggle').setAttribute("onclick", "pxruler()");
	document.body.removeAttribute("onmousedown");
	document.body.removeAttribute("onmousemove");
	document.body.removeAttribute("onmousewheel");
}
//点击时记录位置,并切换操作点
function selecting(event){
	x3 = event.clientX || window.event.clientX;
	x3 += document.documentElement.scrollLeft || document.body.scrollLeft;
	y3 = event.clientY || window.event.clientY;
	y3 += document.documentElement.scrollTop || document.body.scrollTop;
	document.getElementById("point3").style.left = x3 -4 + "px";
	document.getElementById("point3").style.top = y3 -4 + "px";
	document.getElementById('point3xy').innerHTML='x3:' + x3 + ' y3:' + y3;
}
function setpoint1(event){
	x1 = x3;
	y1 = y3;
	document.getElementById('point1').style.left = x1 - 4 + "px";
	document.getElementById('point1').style.top = y1 - 4 + "px";
	document.getElementById('point3').style.backgroundColor = "#66ccff";
	document.body.setAttribute("onmousedown", "setpoint2(event)");
	document.getElementById('point1xy').innerHTML='x1:' + x1 + ' y1:' + y1;
	document.getElementById('deltaxy').innerHTML='Δx:' + (x2-x1) + ' Δy:'+ (y2-y1);
}
function setpoint2(event){
	x2 = x3;
	y2 = y3;
	document.getElementById('point2').style.left = x2 - 4 + "px";
	document.getElementById('point2').style.top = y2 - 4 + "px";
	document.getElementById('point3').style.backgroundColor = "#ee0000";
	document.body.setAttribute("onmousedown", "setpoint1(event)");
	document.getElementById('point2xy').innerHTML='x2:' + x2 + ' y2:' + y2;
	document.getElementById('deltaxy').innerHTML='Δx:' + (x2-x1) + ' Δy:'+ (y2-y1);
}