User:Koavf/simplife.js

var xwLang = 'simple'; $(function {   var wgPageName = mw.config.get('wgPageName');    mw.util.addPortletLink('p-cactions', 'http://' + xwLang + '.wikipedia.org/wiki/' + mw.config.get('wgPageName'), 'simple', 'ca-x' + xwLang)    wpPageExists(wgPageName); });

function wpPageExists(title) { var url = 'http://' + xwLang + '.wikipedia.org/w/api.php?action=query&format=json&callback=wpPageExistsCb&titles=' + title; var scriptElem = document.createElement('script'); scriptElem.setAttribute('src', url); scriptElem.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(scriptElem); } function wpPageExistsCb(obj) { var wgPageName = mw.config.get('wgPageName'); var exists = obj['query']['pages']['-1']; var elm = document.getElementById('ca-x' + xwLang); elm.className = exists ? 'new' : ''; elm.firstChild.href = 'http://' + xwLang + '.wikipedia.org/wiki/' + wgPageName + (exists ? '?action=edit' : ''); }