মিডিয়াউইকি:Gadget-collectionparser.js
লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।
- ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
- গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
- ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
- অপেরা: Ctrl-F5 টিপুন।
// 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 = '{{সংরক্ষিত বই}}\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:বইসমূহ]]";
// 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', '#', 'বই প্রস্তুত করুন').click(function() {
getCollection($content);
});
}
}
mw.hook('wikipage.content').add(addPediapressLinks);