မီႇတီႇယႃႇဝီႇၶီႇ:Gadget-collectionparser.js

လုၵ်ႉတီႈ ဝီႇၶီႇပပ်ႉ မႃး
မၢႆတွင်း: ဝၢႆးသေသိမ်းပၼ်ယဝ်ႉ၊ တွၼ်ႈတႃႇ ၸဝ်ႈၵဝ်ႇ တေႁၼ်လႆႈ လွင်ႈလႅၵ်ႈလၢႆႈၼၼ်ႉ ၸဝ်ႈၵဝ်ႇတေၸၢင်ႈလႆႈလတ်းၶၢမ်ႈ ၶႅတ်ႉၶျ် တူဝ်ပိုတ်ႇဝႅပ်ႉၸဝ်ႈၵဝ်ႇယဝ်ႉ။
  • ၽွင်းမိူဝ်ႈတိုၵ်ႉၼဵၵ်း Reload တီႈ Firefox / Safari: ၼၼ်ႉ ၼဵၵ်းဝႆႉပႃး Shift ၊ဢမ်ႇၼၼ် ၼဵၵ်းပၼ် Ctrl-F5 ဢမ်ႇၼၼ် Ctrl-R (တီႈၼႂ်း Mac ၼႆ ၼဵၵ်းပၼ်⌘-R)
  • တီႈၼႂ်း Google Chrome: ၼဵၵ်းပၼ် Ctrl-Shift-R (တီႈၼႂ်း Mac ၼႆႉ ၼဵၵ်းပၼ်⌘-Shift-R )
  • ၽွင်းမိူဝ်ႈ တိုၵ်ႉၼဵၵ်း Refreshတီႈ Internet Explorer/ Edge: ၼဵၵ်းဝႆႉပၼ် Ctrl ဢမ်ႇၼၼ် ၼဵၵ်းပၼ် Ctrl-F5
  • တီႈၼႂ်း Opera: ၵႂႃႇၸူးတီႈ Menu → Settings (ပေႃးပဵၼ်တီႈၼႂ်း Mac ၸိုင် Opera → Preferences ) သေ သိုပ်ႇၵႂႃႇ Privacy & security → Clear browsing data → Cached images and files ၼၼ်ႉလႄႈ။
// Adapted from User:Pediapress/collection-parser.js

function putOutList(list) {
	var bookURL = mw.config.get('wgServer') + mw.util.getUrl( mw.config.get( 'wgBookName' ) );
	var pathRE;
	var pagename, bookname = list[0].replace(/_/g, " ");
	var out = '{{saved book}}\n' + '== ' + bookname +' ==\n:[[' + bookname + ']]\n';
	
	bookURL = $.escapeRE(bookURL);
	pathRE = new RegExp( '^https?:' + bookURL + '\\/' );
	list.shift();
	$.each( list, function(i) {
		if ( this.match(pathRE) ) {
			pagename = this.replace(pathRE, '').replace(/_/g, " ");
			out += ":[[" + bookname + "/" + pagename + "|" + pagename + "]]\n";
		} else if ( list[i+1] && list[i+1].match(pathRE) && $.trim(this) !== "" ) {
			// kick out empty headlines and those without links
			out += ";" + this + "\n";
		}
	});
	
	out += "\n[[Category:Collections]]";

	// print the collectionmarkup into a textarea
	var collectionName = prompt("Name your collection:", "");
	if (collectionName) {
		var w = window.open(mw.config.get('wgServer') + "/w/index.php?title=User:" + mw.config.get('wgUserName') + "/Collections/" + collectionName + "&action=edit");
		$(w).on( 'load', function() { refreshTextArea(w, out); } );
	}
}
 
function refreshTextArea(w, out) {
	var txt = w.document.getElementById('wpTextbox1');
	txt.value = out;
} 

// look for headlines and links
function parseContent ($content) {
	var bookURL = mw.config.get('wgServer') + mw.util.getUrl( mw.config.get( 'wgBookName' ) );
	var bookLinks = [mw.config.get( 'wgBookName' )];
	var pathRE;
	
	bookURL = $.escapeRE(bookURL);
	pathRE = new RegExp( '^https?:' + bookURL + '$|^https?:' + bookURL + '\\/' );
	
	$.each( $content.find(".mw-headline, a"), function() {
		var $this = $(this), val;
		
		if ( $this.is('.mw-headline') ) {
			bookLinks[bookLinks.length] = $this.html() || 'chapter';
		} else if ( $this.is('a') && this.href.match(pathRE) && !this.href.match(/#/) ) {
			bookLinks[bookLinks.length] = this.href;
		}
	});
	
	return bookLinks;
}

// added link has been clicked
function getCollection($content) {
	putOutList(parseContent($content));
}
 
// add an link at thr right upper corner
function addPediapressLinks($content) {
	if ( $.inArray( mw.config.get('wgNamespaceNumber'), [ 0, 102, 110 ] ) !== -1 ) {
		$(mw.util.addPortletLink ('p-personal', '#', 'get collection')).click(function() {
			getCollection($content);
		});
	}
}

mw.hook('wikipage.content').add(addPediapressLinks);