「MediaWiki:Mobile.js」:修訂間差異
跳至導覽
跳至搜尋
無編輯摘要 |
無編輯摘要 |
||
第173行: | 第173行: | ||
* with MobileFrontend extension before MediaWiki 1.42. | * with MobileFrontend extension before MediaWiki 1.42. | ||
*/ | */ | ||
mw.loader.using( | |||
[ | |||
'mediawiki.api', | |||
'mediawiki.jqueryMsg' | |||
], | |||
function ( require ) { | |||
return new mw.Api().loadMessagesIfMissing( [ | |||
"darkmode-link", | |||
"darkmode-link-tooltip", | |||
"darkmode-default-link", | |||
"darkmode-default-link-tooltip" | |||
] ); | |||
} | |||
); | |||
mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode.styles&only=styles&raw=1', 'text/css' ); | mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode.styles&only=styles&raw=1', 'text/css' ); | ||
mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode&only=scripts&raw=1' ); | mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode&only=scripts&raw=1' ); |
於 2024年4月28日 (日) 23:30 的修訂
/* 此 JavaScript 會用於使用者載入的每一個頁面。 */
/** 指定執行順序*/
$(function(){
addPurgeLink();
});
/** 在頁首插入清除快取的連結,以代替側邊列失效的功能*/
function addPurgeLink(){
// 抓取頁面全名
var pageTitle = mw.config.get('wgPageName');
// 將半形問號取代為「%3F」,以使連結正常
pageTitle = pageTitle.replace(/\?/g,"%3F");
// 在頁首的功能列加入「清理快取」連結
// <li id="ca-view" class="selected"><span><a href="/%E6%A8%A1%E6%9D%BF:Vote">閱讀</a></span></li>
$("#p-views-label").next("ul").prepend(
$("<li id=\"ca-purge\"></li>").append(
$("<span></span>").append("<a href=\"/"+pageTitle+"?action=purge\">清理快取</a>")
)
);
// 如果是purge(清除快取)頁面,則將「閱讀」取消強調,並強調「清理快取」
if(mw.config.get('wgAction') == "purge"){
$("#ca-purge").addClass("selected");
$("#ca-view").removeClass("selected");
console.log("wgAction == purge");
}
}
function ModifySidebar( action, section, name, link, number ) {
try {
switch ( section ) {
case 'languages':
var target = 'p-lang';
break;
case 'toolbox':
var target = 'p-tb';
break;
case 'navigation':
var target = 'p-navigation';
break;
default:
var target = 'p-' + section;
break;
}
if ( action == 'add' ) {
var node = document.getElementById( target )
.getElementsByTagName( 'div' )[0]
.getElementsByTagName( 'ul' )[0];
var aNode = document.createElement( 'a' );
var liNode = document.createElement( 'li' );
aNode.appendChild( document.createTextNode( name ) );
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
liNode.className = 'plainlinks' + number;
liNode.id = 'plainlinks' + number
node.appendChild( liNode );
}
if ( action == 'remove' ) {
var list = document.getElementById( target )
.getElementsByTagName( 'div' )[0]
.getElementsByTagName( 'ul' )[0];
var listelements = list.getElementsByTagName( 'li' );
for ( var i = 0; i < listelements.length; i++ ) {
if (
listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
listelements[i].getElementsByTagName( 'a' )[0].href == link
)
{
list.removeChild( listelements[i] );
}
}
}
} catch( e ) {
// let's just ignore what's happened
return;
}
}
function CustomizeModificationsOfSidebar() {
// adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
//ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'https://en.wikipedia.org/wiki/Special:CategoryTree' );
// removes [[Special:Upload|Special:Upload]] from toolbox
//ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://en.wikipedia.org/wiki/Special:Upload' );
//ModifySidebar('remove', '近期變更','近期變更','recentchanges-url|recentchanges');
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlDoc = this.responseXML;
var x = xmlDoc.getElementsByTagName("rc");
var i;
var name = "";
var date1;
var day;
var month;
var year;
var checkday;
var date2;
var number;
var h3=document.createElement("LI");
h3.style.marginTop="10px";
h3.style.marginBottom="4px";
h3.style.marginRight="20px";
h3.style.fontSize="14px";
h3.style.fontWeiget="bold";
h3.style.color="#6a6a6a";
// h3.style.backgroundImage="linear-gradient(to right,rgba(200,204,209,0) 0,#c8ccd1 33%,#c8ccd1 66%,rgba(200,204,209,0) 100%)";
// h3.style.backgroundRepeat="no-repeat";
// h3.style.backgroundPosition="center bottom";
// h3.style.backgroundSize="100% 1px";
var texth3=document.createTextNode("最近20則變更");
h3.appendChild(texth3);
h3.className = "rc20";
document.getElementById("n-所有變更").appendChild(h3);
date1 = new Date(x[0].getAttribute('timestamp'));
day = date1.getDate();
month = date1.getMonth() + 1;
year = date1.getFullYear();
date2 = year + "年" + month + "月" + day + "日";
var h31=document.createElement("LI");
h31.style.marginTop="3px";
h31.style.fontSize="12px";
h31.style.color="#6a6a6a";
var texth31=document.createTextNode(date2);
h31.appendChild(texth31);
h31.className = "date" + i;
document.getElementById("n-所有變更").appendChild(h31);
checkday = day;
var listid = 0;
var listname = "";
var h32=document.createElement("LI");
h32.style.marginTop="4px";
h32.style.marginBottom="1px";
h32.style.fontSize="14px";
h32.style.color="#54595d";
for(i = 0; i < x.length; i++){
name = x[i].getAttribute('title');
date1 = new Date(x[i].getAttribute('timestamp'));
day = date1.getDate();
if(checkday != day){
month = date1.getMonth() + 1;
year = date1.getFullYear();
date2 = year + "年" + month + "月" + day + "日";
var texth32=document.createTextNode(date2);
h32.appendChild(texth32);
h32.className = "date" + i;
listid = i - 1;
listname = "plainlinks" + listid;
document.getElementById(listname).appendChild(h32);
checkday = day;
}
ModifySidebar('add','近期變更', name,'https://rekowiki.org/wiki/'+name, i);
}
}
};
xhttp.open("GET", "https://rekowiki.org/w/api.php?action=query&format=xml&list=recentchanges&rcdir=older&rcprop=title%7Ctimestamp&rclimit=20&rctype=edit%7Cnew&rctoponly=1", true);
xhttp.send();
}
jQuery( CustomizeModificationsOfSidebar );
/**
* Force DarkMode load on mobile
* DarkMode styles and scripts won't load on mobile
* with MobileFrontend extension before MediaWiki 1.42.
*/
mw.loader.using(
[
'mediawiki.api',
'mediawiki.jqueryMsg'
],
function ( require ) {
return new mw.Api().loadMessagesIfMissing( [
"darkmode-link",
"darkmode-link-tooltip",
"darkmode-default-link",
"darkmode-default-link-tooltip"
] );
}
);
mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode.styles&only=styles&raw=1', 'text/css' );
mw.loader.load( 'https://rekowiki.org/w/load.php?modules=ext.DarkMode&only=scripts&raw=1' );