Loading...

Wikipedia quick cite page bookmark


I am tying to make a bookmark that dose something similar to this on 9xbuddy, but I want it for the cite page feature on Wikipedia, this is what I have:

javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=/'+ document.location.href); })();

but if you were to try and use the thing, it almost works. The problem is the page ID's so what I'm wandering is, is it possible to make the bookmark fetch them or no?

Thanks in advance (also run the snippet below to easily test it; so you can see exactly what the result is when the bookmark is used)

$(".selectable").click(function() {
    $(this).select();
});
$(document).ready(function () {
    var selectcounter = 1;
    
    $(".selectable").each(function() {
        idja = "selectable" + selectcounter;
        $(this).attr('id', idja);
        $(this).attr('onclick', 'selectText("' + idja + '")');
        selectcounter++;
    });     
});

function selectText(containerid) {
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(containerid));
        range.select();
    } else if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(document.getElementById(containerid));
        window.getSelection().addRange(range);
    }
}
.selectable {
    cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
click below text to select it, then drag into bookmarks bar to add as bookmark
<p class="selectable">javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page=/'+ document.location.href); })();</p>

- - Source

Answers

answered 1 week ago mwoelk #1

You can use this as bookmark:

javascript:(function(){ window.open('https://en.wikipedia.org/wiki/Special:CiteThisPage?page='+ document.location.href.substr(document.location.href.lastIndexOf('/') + 1)); })();

answered 1 week ago izem #2

Use pathname and not href, and then replace /wiki/ with empty string:

document.location.pathname.replace(/^\/wiki\//, ''))

Full bookmark:

javascript:(function(){ window.open('https://en.wikipedia.org/w/index.php?title=Special:CiteThisPage&page='+ document.location.pathname.replace(/^\/wiki\//, '')); })();

comments powered by Disqus