Qualitätswoche: Artikel verbessern und Crunchyroll-Premium-Abo gewinnen!
Verbessere im Rahmen der Qualitätswoche einen Artikel deiner Wahl und gewinne mit etwas |
Benutzer:Totto/common.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Inhalt hinzugefügt Inhalt gelöscht
Totto (Diskussion | Beiträge) K (onlinecounter) |
Totto (Diskussion | Beiträge) K (error?) |
||
Zeile 29: | Zeile 29: | ||
//addHotkey("p","preview"); |
//addHotkey("p","preview"); |
||
//AddAcessKeys(); |
//AddAcessKeys(); |
||
− | onlinecounter() |
+ | onlinecounter(); |
} |
} |
||
Zeile 111: | Zeile 111: | ||
} |
} |
||
function refresh(){ |
function refresh(){ |
||
− | onlinecounter() |
+ | onlinecounter(); |
} |
} |
||
function onlinecounter(){ |
function onlinecounter(){ |
||
var url="https://conanwiki.org/wiki/Spezial:Wer_ist_gerade_online" |
var url="https://conanwiki.org/wiki/Spezial:Wer_ist_gerade_online" |
||
− | fetch(url).then( |
+ | fetch(url).then((response)=> { |
// The API call was successful! |
// The API call was successful! |
||
return response.text(); |
return response.text(); |
||
− | }).then( |
+ | }).then((html)=> { |
var num=0; |
var num=0; |
||
// Convert the HTML string into a document object |
// Convert the HTML string into a document object |
||
Zeile 125: | Zeile 125: | ||
var doc = parser.parseFromString(html, 'text/html'); |
var doc = parser.parseFromString(html, 'text/html'); |
||
var cont=document.getElementById("TottoOnlineCounter").getElementsByTagName("a")[0]; |
var cont=document.getElementById("TottoOnlineCounter").getElementsByTagName("a")[0]; |
||
− | var c=doc.getElementById("mw-content-text") |
+ | var c=doc.getElementById("mw-content-text"); |
− | num=c.getElementsByTagName("ul")[0].getElementsByTagName("li").length |
+ | num=c.getElementsByTagName("ul")[0].getElementsByTagName("li").length; |
cont.innerHTML=num; |
cont.innerHTML=num; |
||
− | console.log(num) |
+ | console.log(num); |
− | }).catch( |
+ | }).catch( (err)=> { |
// There was an error |
// There was an error |
||
console.warn('Something went wrong.', err); |
console.warn('Something went wrong.', err); |
Version vom 17. April 2021, 23:14 Uhr
function mainTotto(){ var tf=document.getElementById("p-personal"); var containerQuickJump= tf.getElementsByTagName("ul")[0]; var container = document.createElement("li"); container.setAttribute("class","TottoCustomContainer"); container.innerHTML='<a href="/wiki/ConanWiki:NextHints" dir="auto" title="Quick Acess Hints" >Hints</a>'; container.setAttribute("id","TottoHints"); containerQuickJump.prepend(container); var container2 = document.createElement("li"); container2.setAttribute("class","TottoCustomContainer"); container2.innerHTML='<a href="/wiki/Vorlage:Anime-JP" dir="auto" title="Quick Acess Vorlage JP" >Vorlage JP</a>'; container2.setAttribute("id","TottoVorlageJP"); containerQuickJump.prepend(container2); var container3 = document.createElement("li"); container3.setAttribute("class","TottoCustomContainer"); container3.innerHTML='<a onclick="scrollToBottom();" dir="auto" title="Quick Acess Down" >Downscroll</a>'; container3.setAttribute("id","TottoScrollDown"); containerQuickJump.prepend(container3); var container4 = document.createElement("li"); container4.setAttribute("class","TottoCustomContainer"); container4.innerHTML='<a onclick="onlinecounter()" dir="auto" title="Online Counter">0</a>'; container4.setAttribute("id","TottoOnlineCounter"); containerQuickJump.prepend(container4); //addHotkey("s","scrollToBottom"); //addHotkey("u","scrollToTop"); //addHotkey("p","preview"); //AddAcessKeys(); onlinecounter(); } function preview(){ var ed= document.getElementsByClassName("editButtons"); if(ed.length>=1){ ///Auto HotkeyPreview Preview :yum: var previewbt=document.getElementById("wpPreview"); previewbt.click(); } } function addToQuicklink(title,link){ var tf=document.getElementById("p-personal"); var containerQuickJump= tf.getElementsByTagName("ul")[0]; var container = document.createElement("li"); container.setAttribute("class","TottoCustomContainer"); container.innerHTML='<a href="'+link+'" dir="auto" title="Quick Acess '+title+'" >'+title+'</a>'; container.setAttribute("id","TottoHints"); containerQuickJump.prepend(container); } function scrollToBottom(){ window.scrollTo(0,document.body.scrollHeight); } function scrollToTop(){ window.scrollTo(0,document,0) } function addHotkey(hotkey,function_to_call){ var num= hotkey.toUpperCase().charCodeAt(0); document.addEventListener("keydown", function(event) { const key = event.keyCode; if(key===num&&event.altKey&&event.shiftKey){ window[function_to_call](); } } ); } function addHotkeyF(hotkey,function_to_call){ var num= hotkey.toUpperCase().charCodeAt(0); document.addEventListener("keydown", function(event) { const key = event.keyCode; if(key===num&&event.altKey&&event.shiftKey){ function_to_call(); } } ); } function getAllElementsWithAttribute(attribute){ var matchingElements = []; var allElements = document.getElementsByTagName('*'); for (var i = 0, n = allElements.length; i < n; i++){ if (allElements[i].getAttribute(attribute) !== null) { // Element exists with attribute. Add to array. matchingElements.push(allElements[i]); } } return matchingElements; } function clickf(elementr){ elementr.click(); } function AddAcessKeys(){ var t= getAllElementsWithAttribute("accesskey"); for(var i=0;i<t.length;i++){ var key=t[i].getAttribute("accesskey"); if(key!="."&&key!=""){ addHotkeyF(key,clickf(t[i])); } } } function refresh(){ onlinecounter(); } function onlinecounter(){ var url="https://conanwiki.org/wiki/Spezial:Wer_ist_gerade_online" fetch(url).then((response)=> { // The API call was successful! return response.text(); }).then((html)=> { var num=0; // Convert the HTML string into a document object var parser = new DOMParser(); var doc = parser.parseFromString(html, 'text/html'); var cont=document.getElementById("TottoOnlineCounter").getElementsByTagName("a")[0]; var c=doc.getElementById("mw-content-text"); num=c.getElementsByTagName("ul")[0].getElementsByTagName("li").length; cont.innerHTML=num; console.log(num); }).catch( (err)=> { // There was an error console.warn('Something went wrong.', err); document.getElementById("TottoOnlineCounter").getElementsByTagName("a")[0].innerHTML=0; }); } mainTotto();