利用者:タバコはマーダー/revisionShortener.js
表示
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
// 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);
}
}