「利用者:島田「にかい」/common.js」の版間の差分
ナビゲーションに移動
検索に移動
>島田「にかい」 編集の要約なし |
>島田「にかい」 編集の要約なし |
||
80行目: | 80行目: | ||
} | } | ||
}); | }); | ||
/** | |||
* サイドバーに表示中ページのサブページ一覧 ([[特別:前方一致ページ一覧]]) へのリンクを追加する。 | |||
*/ | |||
$.when( mw.loader.using( ['mediawiki.util'] ), $.ready ).then(function() { | |||
if( mw.config.get( 'wgNamespaceNumber' ) !== -1 ) { | |||
var url = mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace( '$1', 'Special:PrefixIndex/' ) + mw.config.get( 'wgPageName' ) + '/'; | |||
mw.util.addPortletLink( 'p-tb', url, '前方一致ページ一覧', 't-prefixindexlink', 'このページのサブページ一覧' ); | |||
} | |||
}); | |||
// revisionShortener (カスタムJS/User script) | |||
// 差分や過去版を表示した際に、ウィキペディアのノートページで使用できるそのページの短いリンクを生成する。 | |||
// This script generates a short diffPage address. Supported En. | |||
// 使用説明(Usage) : [[User:タバコはマーダー/revisionShortener]] | |||
// Date 2016-09-27 | |||
$(document).ready(function(){ | |||
revisionShortener(); | |||
}); | |||
function revisionShortener(delTitle, delHour, viewAll) { | |||
if ( mw.config.get("wgAction") == "edit" ) return; | |||
var u = location; | |||
if (u.search === "") return; | |||
// variable by Mediawiki | |||
var sPageName = mw.config.get("wgRelevantPageName"); | |||
var sWPLang = mw.config.get("wgContentLanguage"); | |||
var currentSkinName = mw.config.get("skin"); | |||
// class name by Mediawiki | |||
var classNameDiffPageTime = "diff-currentversion-title"; // newer time, have oldid and diff parameter. | |||
var idNameOldidSingleTime = "mw-revision-date"; // time, have oldid only. | |||
var classNameDiffMulti = "diff-multi"; // Detect there is a revision between oldid and diffid. | |||
var targetElementViewShortenerBox = "content"; | |||
if (currentSkinName == "modern") { | |||
targetElementViewShortenerBox = "mw-content-text"; | |||
} | |||
var sTime = getRevisionTime(classNameDiffPageTime, idNameOldidSingleTime); | |||
if (sTime == undefined) return; // bug fix report by User:MawaruNeko | |||
// for loacal setting | |||
var thisScriptTitle = ""; | |||
var LocalSpecialDiff = "Special:Diff"; | |||
var LocalTemplateDiff = "diff"; // in en, template:diff, | |||
if (sWPLang == "en") { | |||
if (sTime.indexOf(" of ") != -1) | |||
sTime = sTime.split(" of ")[1]; // Convert to time only. In en. | |||
} | |||
if (sWPLang == "ja") { // e.g. | |||
LocalSpecialDiff = "特別:差分"; | |||
LocalTemplateDiff = "差分"; | |||
if (sTime.indexOf("時点").indexOf != -1) | |||
sTime = sTime.split("時点")[0].replace(/ \(.\) /,""); // Convert to time only . In ja, delete day of week. | |||
document.title = document.title.slice(0, -9) + sTime; | |||
} | |||
var colorViewer = "#ecf4fa", colorViewerBorder = "#a7d7f9"; | |||
if (currentSkinName == "cologneblue") | |||
colorViewer = "#ffffff", colorViewerBorder = "#a9a9a9"; | |||
function getRevisionTime(id1, id2) { | |||
id1 = "." + id1, id2 = "#" + id2; | |||
if ($(id1).length !== 0) | |||
return $(id1).text(); | |||
if ($(id2).length !== 0) | |||
return $(id2).text(); | |||
} | |||
function splitParam(objUrl) { | |||
var uParam = objUrl.search.slice(1); // delete "?" | |||
var aParam = uParam.split("&"); | |||
var a = []; | |||
for (var i in aParam) { | |||
var t = aParam[i].split("="); | |||
a.push(t); | |||
} | |||
return a; | |||
} | |||
function pickupCell(a, index) { | |||
for (var i in a) | |||
if (a[i][0] == index) | |||
return a[i][1]; | |||
return false; | |||
} | |||
function convParam(diffid, oldid, mode) { | |||
switch (mode){ | |||
case "sp": | |||
if (diffid == "prev") | |||
return oldid; | |||
return oldid + "/" + diffid; | |||
case "tm": | |||
return diffid + "|" + oldid; | |||
case "uri": | |||
if (diffid == "prev") | |||
return "diff=" + oldid; | |||
return "diff=" + diffid + "&" + "oldid=" + oldid; | |||
} | |||
} | |||
var aParam = splitParam(u); | |||
var diffid = pickupCell(aParam, "diff"); | |||
var oldid = pickupCell(aParam, "oldid"); | |||
if (!oldid && !diffid) return; | |||
if (oldid === "prev") { // for diff page from noftication page. it's reversed. | |||
oldid = diffid; | |||
diffid = "prev"; | |||
} | |||
if (delHour) { | |||
sTime = sTime.replace(/[012][0-9]:[0-6][0-9]/, ""); | |||
if (sTime.indexOf(",").indexOf != -1) | |||
sTime = sTime.replace(/, /,""); | |||
} | |||
var uAll = u.href.split("?"); | |||
var uAddres = uAll[0].replace("index.php", ""); | |||
var isMultiRev = ($("." + classNameDiffMulti).length !== 0 ? true : false); | |||
if ( !isMultiRev && isNaN(diffid) === false){ | |||
oldid = Math.max( diffid, oldid ); | |||
diffid = "prev"; | |||
} else if (!oldid && isNaN(diffid) === false) { | |||
oldid = diffid; | |||
diffid = "prev"; | |||
} else if (!diffid) { | |||
diffid = "prev"; | |||
} | |||
var sLabel = (delTitle ? "" : sPageName + "(") + sTime + (delTitle ? "" : ")"); | |||
var sRevSpecial = "[[" + LocalSpecialDiff + "/" + convParam(diffid, oldid, "sp") + "|" + sLabel + "]]"; | |||
var sRevTemplate = "{{" + LocalTemplateDiff + "|" + sPageName + "|" + convParam(diffid, oldid, "tm") + "|" + sLabel + "}}"; | |||
var sRevURI = "[" + uAddres + "?" + convParam(diffid, oldid, "uri") + " " + sLabel + "]"; | |||
var viewer = "<p><input id=\"rv_url1\" class=\"revisionShortener\"></p>" + | |||
(viewAll ? "<p><input id=\"rv_url2\" class=\"revisionShortener\"></p>" + | |||
"<p><input id=\"rv_url3\" class=\"revisionShortener\"></p>" : "" ); | |||
var checkbox = thisScriptTitle + "<input type=\"checkbox\" id=\"view_title\" " + (delTitle ? "" : "checked=\"checked\"") + "><label for=\"view_title\">title</label>" + | |||
"<input type=\"checkbox\" id=\"view_time\" " + (delHour ? "" : "checked=\"checked\"") + "><label for=\"view_time\">time</label>" + | |||
"<input type=\"checkbox\" id=\"view_version\" " + (viewAll ? "" : "checked=\"checked\"") + "><label for=\"view_version\">simple</label>"; | |||
if ($("#shortenerBox").length === 0) | |||
if (currentSkinName == "cologneblue") | |||
$("h1").before("<div id=\"shortenerBox\"></div>"); | |||
else | |||
$("#" + targetElementViewShortenerBox).prepend("<div id=\"shortenerBox\"></div>"); | |||
$("#shortenerBox").css({ "width" : "100%", "padding" : "10px 0", "margin-left":"20px" }).html(checkbox + viewer); | |||
$("#shortenerBox p").css({ "padding" : "0", "margin":"4px 0" }); | |||
$("#shortenerBox label").css({ "font-size":"88%", "margin-right":"10px" }); | |||
$("#view_title, #view_time, #view_version").css({ "vertical-align":"middle", "margin":"0 3px 0 0" }); | |||
$("input.revisionShortener").css({ "width": "400px", "border":"1px solid " + colorViewerBorder, "background-color": colorViewer }).focus(function(){ | |||
$(this).select(); | |||
}); | |||
function checkboxFunc() { | |||
var ck1 = ( $("#view_title").prop("checked") ? false : true); | |||
var ck2 = ( $("#view_time").prop("checked") ? false : true); | |||
var ck3 = ( $("#view_version").prop("checked") ? false : true); | |||
revisionShortener(ck1, ck2, ck3); | |||
} | |||
$("#view_title").click(checkboxFunc); | |||
$("#view_time").click(checkboxFunc); | |||
$("#view_version").click(checkboxFunc); | |||
$("#rv_url1").val(sRevSpecial); | |||
if (viewAll) { | |||
$("#rv_url2").val(sRevTemplate); | |||
$("#rv_url3").val(sRevURI); | |||
} | |||
} |
2021年11月4日 (木) 10:17時点における最新版
// ページ名の左に保護状態を表示する
$(function()
{
// 編集状態の規定値
var editptext = '無';
var moveptext = '無';
var editpcolor = 'cccccc';
var editpcolor = 'cccccc';
var protected = false;
var wgRestrictionMove = mw.config.get( 'wgRestrictionMove', [] );
var wgRestrictionEdit = mw.config.get('wgRestrictionEdit', []);
// 編集保護状態
switch(wgRestrictionEdit[0])
{
// 半保護
case 'autoconfirmed':
editptext = '半';
editpcolor = 'ffff55';
protected = true;
break;
// 全保護
case 'sysop':
editptext = '全';
editpcolor = 'ff5555';
protected = true;
break;
}
// 移動保護状態
switch(wgRestrictionMove[0])
{
// 半保護
case 'autoconfirmed':
moveptext = '半';
movepcolor = 'ffff55';
protected = true;
break;
// 全保護
case 'sysop':
moveptext = '全';
movepcolor = 'ff5555';
protected = true;
break;
}
// 保護されていれば
if(protected)
{
// 表生成
var table = document.createElement('table');
// class, id およびスタイルを設定
table.setAttribute("class", "noprint");
table.setAttribute("id", "protectionStatus");
table.setAttribute("style", "font-size: 45%; float: left; line-height: 60%;");
table.setAttribute("cellspacing", 0);
// 中身を生成
table.innerHTML = '<tbody><tr style=\"background-color: #'
+ editpcolor
+ '\" id=\"LWeditprtected\"><th style="padding: 4px; font-weight: normal;\">編集</th><td style=\"padding: 4px;\">'
+ editptext
+ '</td></tr><tr style=\"background-color: #'
+ movepcolor
+ '\" id=\"LWmoveprtected\"><th style=\"padding: 4px; font-weight: normal;\">移動</th><td style=\"padding: 4px;\">'
+ moveptext
+ '</td></tr></tbody></table>';
// ページ名<h1>取得
var firstHeading = document.getElementById("firstHeading");
// ページ名の左に表を表示
firstHeading.insertBefore(table, firstHeading.firstNode);
}
});
/**
* サイドバーに表示中ページのサブページ一覧 ([[特別:前方一致ページ一覧]]) へのリンクを追加する。
*/
$.when( mw.loader.using( ['mediawiki.util'] ), $.ready ).then(function() {
if( mw.config.get( 'wgNamespaceNumber' ) !== -1 ) {
var url = mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace( '$1', 'Special:PrefixIndex/' ) + mw.config.get( 'wgPageName' ) + '/';
mw.util.addPortletLink( 'p-tb', url, '前方一致ページ一覧', 't-prefixindexlink', 'このページのサブページ一覧' );
}
});
// revisionShortener (カスタムJS/User script)
// 差分や過去版を表示した際に、ウィキペディアのノートページで使用できるそのページの短いリンクを生成する。
// This script generates a short diffPage address. Supported En.
// 使用説明(Usage) : [[User:タバコはマーダー/revisionShortener]]
// Date 2016-09-27
$(document).ready(function(){
revisionShortener();
});
function revisionShortener(delTitle, delHour, viewAll) {
if ( mw.config.get("wgAction") == "edit" ) return;
var u = location;
if (u.search === "") return;
// variable by Mediawiki
var sPageName = mw.config.get("wgRelevantPageName");
var sWPLang = mw.config.get("wgContentLanguage");
var currentSkinName = mw.config.get("skin");
// class name by Mediawiki
var classNameDiffPageTime = "diff-currentversion-title"; // newer time, have oldid and diff parameter.
var idNameOldidSingleTime = "mw-revision-date"; // time, have oldid only.
var classNameDiffMulti = "diff-multi"; // Detect there is a revision between oldid and diffid.
var targetElementViewShortenerBox = "content";
if (currentSkinName == "modern") {
targetElementViewShortenerBox = "mw-content-text";
}
var sTime = getRevisionTime(classNameDiffPageTime, idNameOldidSingleTime);
if (sTime == undefined) return; // bug fix report by User:MawaruNeko
// for loacal setting
var thisScriptTitle = "";
var LocalSpecialDiff = "Special:Diff";
var LocalTemplateDiff = "diff"; // in en, template:diff,
if (sWPLang == "en") {
if (sTime.indexOf(" of ") != -1)
sTime = sTime.split(" of ")[1]; // Convert to time only. In en.
}
if (sWPLang == "ja") { // e.g.
LocalSpecialDiff = "特別:差分";
LocalTemplateDiff = "差分";
if (sTime.indexOf("時点").indexOf != -1)
sTime = sTime.split("時点")[0].replace(/ \(.\) /,""); // Convert to time only . In ja, delete day of week.
document.title = document.title.slice(0, -9) + sTime;
}
var colorViewer = "#ecf4fa", colorViewerBorder = "#a7d7f9";
if (currentSkinName == "cologneblue")
colorViewer = "#ffffff", colorViewerBorder = "#a9a9a9";
function getRevisionTime(id1, id2) {
id1 = "." + id1, id2 = "#" + id2;
if ($(id1).length !== 0)
return $(id1).text();
if ($(id2).length !== 0)
return $(id2).text();
}
function splitParam(objUrl) {
var uParam = objUrl.search.slice(1); // delete "?"
var aParam = uParam.split("&");
var a = [];
for (var i in aParam) {
var t = aParam[i].split("=");
a.push(t);
}
return a;
}
function pickupCell(a, index) {
for (var i in a)
if (a[i][0] == index)
return a[i][1];
return false;
}
function convParam(diffid, oldid, mode) {
switch (mode){
case "sp":
if (diffid == "prev")
return oldid;
return oldid + "/" + diffid;
case "tm":
return diffid + "|" + oldid;
case "uri":
if (diffid == "prev")
return "diff=" + oldid;
return "diff=" + diffid + "&" + "oldid=" + oldid;
}
}
var aParam = splitParam(u);
var diffid = pickupCell(aParam, "diff");
var oldid = pickupCell(aParam, "oldid");
if (!oldid && !diffid) return;
if (oldid === "prev") { // for diff page from noftication page. it's reversed.
oldid = diffid;
diffid = "prev";
}
if (delHour) {
sTime = sTime.replace(/[012][0-9]:[0-6][0-9]/, "");
if (sTime.indexOf(",").indexOf != -1)
sTime = sTime.replace(/, /,"");
}
var uAll = u.href.split("?");
var uAddres = uAll[0].replace("index.php", "");
var isMultiRev = ($("." + classNameDiffMulti).length !== 0 ? true : false);
if ( !isMultiRev && isNaN(diffid) === false){
oldid = Math.max( diffid, oldid );
diffid = "prev";
} else if (!oldid && isNaN(diffid) === false) {
oldid = diffid;
diffid = "prev";
} else if (!diffid) {
diffid = "prev";
}
var sLabel = (delTitle ? "" : sPageName + "(") + sTime + (delTitle ? "" : ")");
var sRevSpecial = "[[" + LocalSpecialDiff + "/" + convParam(diffid, oldid, "sp") + "|" + sLabel + "]]";
var sRevTemplate = "{{" + LocalTemplateDiff + "|" + sPageName + "|" + convParam(diffid, oldid, "tm") + "|" + sLabel + "}}";
var sRevURI = "[" + uAddres + "?" + convParam(diffid, oldid, "uri") + " " + sLabel + "]";
var viewer = "<p><input id=\"rv_url1\" class=\"revisionShortener\"></p>" +
(viewAll ? "<p><input id=\"rv_url2\" class=\"revisionShortener\"></p>" +
"<p><input id=\"rv_url3\" class=\"revisionShortener\"></p>" : "" );
var checkbox = thisScriptTitle + "<input type=\"checkbox\" id=\"view_title\" " + (delTitle ? "" : "checked=\"checked\"") + "><label for=\"view_title\">title</label>" +
"<input type=\"checkbox\" id=\"view_time\" " + (delHour ? "" : "checked=\"checked\"") + "><label for=\"view_time\">time</label>" +
"<input type=\"checkbox\" id=\"view_version\" " + (viewAll ? "" : "checked=\"checked\"") + "><label for=\"view_version\">simple</label>";
if ($("#shortenerBox").length === 0)
if (currentSkinName == "cologneblue")
$("h1").before("<div id=\"shortenerBox\"></div>");
else
$("#" + targetElementViewShortenerBox).prepend("<div id=\"shortenerBox\"></div>");
$("#shortenerBox").css({ "width" : "100%", "padding" : "10px 0", "margin-left":"20px" }).html(checkbox + viewer);
$("#shortenerBox p").css({ "padding" : "0", "margin":"4px 0" });
$("#shortenerBox label").css({ "font-size":"88%", "margin-right":"10px" });
$("#view_title, #view_time, #view_version").css({ "vertical-align":"middle", "margin":"0 3px 0 0" });
$("input.revisionShortener").css({ "width": "400px", "border":"1px solid " + colorViewerBorder, "background-color": colorViewer }).focus(function(){
$(this).select();
});
function checkboxFunc() {
var ck1 = ( $("#view_title").prop("checked") ? false : true);
var ck2 = ( $("#view_time").prop("checked") ? false : true);
var ck3 = ( $("#view_version").prop("checked") ? false : true);
revisionShortener(ck1, ck2, ck3);
}
$("#view_title").click(checkboxFunc);
$("#view_time").click(checkboxFunc);
$("#view_version").click(checkboxFunc);
$("#rv_url1").val(sRevSpecial);
if (viewAll) {
$("#rv_url2").val(sRevTemplate);
$("#rv_url3").val(sRevURI);
}
}