JS: Difference between revisions

From ConsoleMods Wiki
Jump to navigation Jump to search
m (Protected "JS" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(Right-click h1 to copy name)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* AUTO HIDE SIDEBAR ON MOBILE */
<nowiki>
if (screen.width < 450) {
/* RIGHT-CLICK HEADER TO COPY URL */
     $('body').addClass("sidebar-collapsed");
document.querySelectorAll("h2, h3, h4, h5, h6").forEach(function(t) {
}
     t.addEventListener("contextmenu",function(e) {
        navigator.clipboard.writeText(window.location.href.split("#")[0]+"#"+t.firstElementChild.id)
    })
});
 
/* RIGHT-CLICK H1 TO COPY NAME */
document.querySelectorAll("h1").forEach(function(t) {
    t.addEventListener("contextmenu",function(e) {
        navigator.clipboard.writeText(window.location.pathname.split('/wiki/')[1])
    })
});


/* TOGGLE HIGHLIGHT ON ORDERED LISTS WHEN CLICKED */
/* TOGGLE HIGHLIGHT ON ORDERED LISTS WHEN CLICKED */
Line 25: Line 35:
     }
     }
});
});
 
</nowiki>
/* HIDE NAMESPACES */
var namespace_name;
$('title').each(function() {
    var page_title = this.innerHTML;
    if (page_title.includes(":") && !page_title.includes("MediaWiki") && !page_title.includes("\"")) {
        namespace_name = page_title.split(':',2)[0];
        var page_name = this.innerHTML = page_title.split(':',2)[1];
        page_name = page_name.replace(" - ConsoleMods Wiki", "");
 
        $('h1#title').each(function() {
            this.innerHTML = page_name;
        });
 
        $('#firstHeading').each(function() {
            this.innerHTML = page_name;
        });
 
        /* COLOR HEADER TITLE */
        if (!page_title.includes("Mods Wiki") && !page_title.includes("ConsoleMods:")) {
            namespace_name = namespace_name.replace("ConsoleMods", "");
        }
 
    } else {
      this.innerHTML = "ConsoleMods Wiki";
    }
});
 
if (namespace_name != undefined && !namespace_name.includes("Special") && !namespace_name.includes("Category") && !namespace_name.includes("File") && !window.location.href.includes("action=history")) {
    $('a[title*=":"]').each(function() {
        var link_page_name = this.innerHTML.split(':',2)[1];
        if (link_page_name != undefined) {
            this.innerHTML = link_page_name;
        }
    });
}
 
/* BACK BUTTON ON TALK PAGES */
$("#ca-talk a").each(function() {
    if (window.location.href.includes("_talk")) {
        this.href = this.href.replace("_talk","");
        $("#ca-talk a span").each(function() { this.innerHTML = "Back to Page" });
    }
    if (window.location.href.includes("Talk:")) {
        this.href = this.href.replace("Talk:","");
        $("#ca-talk a span").each(function() { this.innerHTML = "Back to Page" });
    }
});

Latest revision as of 05:08, 25 October 2024

/* RIGHT-CLICK HEADER TO COPY URL */ document.querySelectorAll("h2, h3, h4, h5, h6").forEach(function(t) { t.addEventListener("contextmenu",function(e) { navigator.clipboard.writeText(window.location.href.split("#")[0]+"#"+t.firstElementChild.id) }) }); /* RIGHT-CLICK H1 TO COPY NAME */ document.querySelectorAll("h1").forEach(function(t) { t.addEventListener("contextmenu",function(e) { navigator.clipboard.writeText(window.location.pathname.split('/wiki/')[1]) }) }); /* TOGGLE HIGHLIGHT ON ORDERED LISTS WHEN CLICKED */ $(":not(.references li) ol li").click(function (e) { e.stopPropagation(); if(!($(this).hasClass("highlighted"))) { $(this).addClass("highlighted"); $(this).find("li").addClass("highlighted"); } else { $(this).removeClass("highlighted"); $(this).find("li").removeClass("highlighted"); } }); /* TOGGLE SIDEBAR VIA CONSOLEMODS TEXT */ $("#footer-partnersico:first-child").click(function (e) { e.stopPropagation(); if(!($('body').hasClass("sidebar-collapsed"))) { $('body').addClass("sidebar-collapsed"); } else { $('body').removeClass("sidebar-collapsed"); } });