Jump to content

User:Technical 13/Scripts/Gadget-veditLinks.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 20:39, 27 December 2014 (Oh, I CAN put it all in one line. Nice. (was having issues before that apparently weren't related.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
$( function( $ ) {
	if(mw.user.options.get("visualeditor-enable") == "1"){
		var thisLink = "";
		var thisLinkTitle = "";
		var thisLinkClass = "";
		var thisLinkVE = "";
		$('span.lx').each(function(){
			thisLink = $(this).find('a:contains("edit")');
			thisLinkTitle = "";
			if(typeof(thisLink.attr('title')) != 'undefined' && thisLink.attr('title') != ''){
				thisLinkTitle = thisLink.attr('title');
			}
			thisLinkClass = "";
			if(typeof(thisLink.attr('class')) != 'undefined' && thisLink.attr('class') != ''){
				thisLinkClass = thisLink.attr('class');
			}
			if(typeof(thisLink.attr('href')) != 'undefined' && thisLink.attr('href') != ''){
				thisLinkVE = thisLink.attr('href').replace('&action=edit', '&veaction=edit');
				thisLink.text('edit source');
				thisLink.after('&nbsp;| <a title="' + thisLinkTitle + '" class="' + thisLinkClass + '" href="' + thisLinkVE + '">edit beta</a>');
				thisLink = "", thisLinkTitle = "", thisLinkClass = "", thisLinkVE = "";
			} else {
				console.warn('No href found for:\n\t%s', $(this).parent().html());
			}
		});
	}
});
//</nowiki>