webaanhaling.js 1.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
(function (){
    if (window.location.href.substring(0, 27) === "https://maroelamedia.co.za/") {
        const titel = document.getElementsByClassName("entry-title single-title")[0].innerText;
        const url = window.location.href;
        const m = document.getElementsByTagName("meta");
        var datum;

        var stuff = document.getElementsByClassName('byline vcard')[0].innerHTML;
        var naam = stuff.match(/&nbsp;\n<a .*>.*<\/a>/, '')[0];
        naam = naam.replace(/&nbsp;\n<a [^>]*>/, '').replace('</a>', '');
        
        for (let i = 0; i < m.length; i++) {
            if (m[i].getAttribute("property") === "article:published_time") {
                datum = m[i].getAttribute("content").substring(0, 10);
            }
        }

        var maande = ['Januarie', 'Februarie', 'Maart', 'April', 'Mei', 'Junie', 'Julie', 'Augustus',
            'September', 'Oktober', 'November', 'Desember'];

        datum = datum.substring(8, 10) + ' ' + maande[Number(datum.substring(5, 7)-1)] + ' ' + datum.substring(0, 4);

        var vandag = new Date();
        var dd = vandag.getDate();
        var mm = vandag.getMonth() - 1;
        var jjjj = vandag.getFullYear();
        

        if (dd<10) {
            dd = '0' + dd;
        } 

        maand = maande[mm];

        vandag = dd + ' ' + maand + ' ' + jjjj;

        const webaanhaling = '{{webaanhaling|url=' + url + '|titel=' + titel + '|werk=[[Maroela Media]]' + '|outeur=' + naam + '|datum=' + datum + '|toegangsdatum=' + vandag + '}}';

        alert(webaanhaling);
    }
})();