ব্যবহারকারী:Arian Writing/Driver1.js
লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।
- ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
- গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
- ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
- অপেরা: Ctrl-F5 টিপুন।
/*
mw.loader.load( "https://meta.wikimedia.org/w/index.php?title=User:Arian_Writing/Driver1.js&action=raw&ctype=text/javascript" );
this.messages = {
'appname': "সূত্রপূরণ",
'heading-options': "বিকল্প",
'label-fixpage': "পাতা ঠিক করুন",
'label-gadgetoptions': "(বিকল্প)"
};
*/
var rlWiki = mw.config.get( "wgContentLanguage" );
function ReflinksGadget() {
this.server = typeof rlServer !== 'undefined' ? rlServer
: "https://tools.wmflabs.org/refill";
this.wiki = typeof rlWiki !== 'undefined' ? rlWiki
: null;
this.portletLink = "";
this.optionsLink = "";
this.messages = {
'appname': "সূত্রপূরণ",
'heading-options': "বিকল্প",
'label-fixpage': "পাতা ঠিক করুন",
'label-gadgetoptions': "(বিকল্প)"
};
this.messagesLoaded = false;
this.suppressConsole = false;
this.log = function( message ) {
if ( !this.suppressConsole ) {
console.log( "Reflinks: " + message );
}
}
this.isWatching = function() {
// Let's use a little hack to determine whether the current page is watched or not
if ( $( "#ca-unwatch" ).length !== 0 ) {
return true;
} else {
return false;
}
}
this.getSubmitUrl = function( defaults ) {
var pagename = mw.config.get( "wgPageName" );
var url = this.server + "/result.php?page=" + encodeURIComponent( pagename );
if ( defaults ) {
url += "&defaults=y";
}
if ( !this.isWatching() ) {
url += "&nowatch=y";
}
if ( this.wiki !== null ) {
url += "&wiki=" + encodeURIComponent( this.wiki );
}
return url;
}
this.msg = function( key ) {
if ( !this.messagesLoaded ) {
this.loadMessages( false );
}
// Even if it's "unloaded", we still have an incomplete set of English messages
if ( this.messages.hasOwnProperty( key ) ) {
return this.messages[key];
} else {
this.log( "Message not found: " + key );
return "[" + key + "]";
}
}
this.loadMessages = function( forceReload ) {
var ts;
try {
ts = localStorage.getItem( "reflinks-messagests" );
} catch (e) {
// LocalStorage can be unavailable for many reasons (full, privacy mode etc)
// Ignore such exceptions
}
if ( !ts || ts < (new Date).getTime() - 259200000 || forceReload ) { // older than 3 days
this.log( "Loading messages from API" );
var obj = this;
$.getJSON( this.server + "/api.php?action=i18n&callback=?", function( data ) {
obj.messages = data;
obj.messagesLoaded = true;
try {
localStorage.setItem( "reflinks-messages", JSON.stringify( data ) );
localStorage.setItem( "reflinks-messagests", (new Date).getTime() );
} catch (e) {
}
} );
} else if ( ts ) { // Cache exists
this.log( "Loading messages from cache @ " + ts );
this.messages = JSON.parse( localStorage.getItem( "reflinks-messages" ) );
this.messagesLoaded = true;
}
}
this.setUpForm = function() {
this.tearDownForm();
var formControls =
$( "#mw-content-text" ).prepend(
$( "<div>" ).attr( "id", "reflinks" ).attr( "style", "border: 1px solid #ccc; border-radius: 2px; margin: 5px; padding: 0 10px 10px 10px;" ).prepend(
$( "<h2>" ).text( this.msg( "heading-options" ) ),
$( "<form>" ).attr( "id", "reflinks-form" ).attr( "method", "post" ).prepend(
$( "<div>" ).attr( "id", "reflinks-options" ).text( this.msg( "loadingoptions" ) ),
$( "<button>" ).addClass( "mw-ui-button mw-ui-progressive" ).text( this.msg( "label-fixpage" ) ),
$( "<a>" ).addClass( "mw-ui-button mw-ui-quiet" ).attr( "href", this.server ).text( this.msg( "label-homepage" ) )
)
)
);
/*
$( "#mw-content-text" ).prepend( "\
<div id='reflinks' style='border: 1px solid #ccc; border-radius: 2px; margin: 5px; padding: 0 10px 10px 10px;'>\
<h2>Options</h1>\
<form id='reflinks-form' method='post'>\
<div id='reflinks-options'>Loading options...</div>\
<input name='method-wiki' type='submit' value='Fix page'/>\
<a href='" + this.server + "' style='color: #555;'>Tool homepage</a>\
</form>\
</div>" );*/
$( "#reflinks-form" ).attr( "action", this.getSubmitUrl( false ) );
if ( !this.isWatching() ) {
var nowatch = $( "<input>" ).attr( "name", "nowatch" ).attr( "type", "hidden" ).val( "y" );
$( "#reflinks-form" ).append( nowatch );
}
$( "html, body" ).animate( {
scrollTop: $( "#reflinks" ).offset().top - 10
}, 250 );
}
this.loadRemoteOptions = function() {
$.getJSON( this.server + "/api.php?action=optionsform&callback=?", function ( json ) {
$( "#reflinks-options" ).html( json.form );
} );
}
this.tearDownForm = function() {
$( "#reflinks" ).remove();
}
this.init = function() {
this.loadMessages( false );
this.portletLink = mw.util.addPortletLink( "p-tb", this.getSubmitUrl( true ), this.msg( "appname" ), "t-reflinks" );
var obj = this;
this.optionsLink = $( "<a>" ).attr( "href", "#" ).text( this.msg( "label-gadgetoptions" ) ).click( function() {
obj.setUpForm();
obj.loadRemoteOptions();
obj.loadMessages( true );
} );
$( this.portletLink ).append( $( "<sup>").html( this.optionsLink ) );
}
}
// Let's put it in global scope for easy debugging
var rlGadget = new ReflinksGadget();
mw.loader.using( 'mediawiki.util' ).then( function () {
rlGadget.init();
} );