ഉപയോക്താവ്:Akhilan/ചൂടൻപൂച്ച.js
ശ്രദ്ധിക്കുക: സേവ് ചെയ്തശേഷം മാറ്റങ്ങൾ കാണാനായി താങ്കൾക്ക് ബ്രൗസറിന്റെ കാഷെ ഒഴിവാക്കേണ്ടി വന്നേക്കാം.
- ഫയർഫോക്സ് / സഫാരി: Reload ബട്ടൺ അമർത്തുമ്പോൾ Shift കീ അമർത്തി പിടിക്കുകയോ, Ctrl-F5 അല്ലെങ്കിൽ Ctrl-R (മാക്കിന്റോഷിൽ ⌘-R ) എന്ന് ഒരുമിച്ച് അമർത്തുകയോ ചെയ്യുക
- ഗൂഗിൾ ക്രോം: Ctrl-Shift-R (മാക്കിന്റോഷിൽ ⌘-Shift-R ) അമർത്തുക
- ഇന്റർനെറ്റ് എക്സ്പ്ലോറർ: Refresh ബട്ടൺ അമർത്തുമ്പോൾ Ctrl കീ അമർത്തിപിടിക്കുക. അല്ലെങ്കിൽ Ctrl-F5 അമർത്തുക
- ഓപ്പറ: Menu → Settings എടുക്കുക (മാക്കിൽ Opera → Preferences) എന്നിട്ട് Privacy & security → Clear browsing data → Cached images and files ചെയ്യുക.
/* Script: [[w:User:TheDJ/Gadget-HotCat.js]]
* HotCat: Adds an easy way to add, modify and remove categories
* Documentation: [[User:TheDJ/HotCat]]
* Originally written by: Magnus Manske
*
* This version was forked from http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&oldid=10204404
* Major changes:
* - blacklist code is disabled.
* - all code for the uploadForm has been removed
* - autocommit is disabled
* - will be enabled on pages without categories so that you can easily add them
* - uses javascript:void() as a dummy value for href in order to avoid a conflict with popups.
* - checks for {{Uncategorized}} and removes it if a category is added
* - does not use JSconfig for configuration options like its Commons original
* - tries to detect other categories and if possible, add to the end of them.
* - fixes a bug in the suggestion list with titles containing : character
* - Uses opensearch API to look for categories. Allows for case insensitive search.
* [[User:TheDJ]] 2008-03-12
<source lang="javascript"><nowiki> */
var hotcat_running = 0 ;
var hotcat_last_v = "" ;
var hotcat_exists_yes = "http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png" ;
var hotcat_exists_no = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/42/P_no.svg/20px-P_no.svg.png" ;
var hotcat_no_autocommit = 0;
// In Commons hotcat_suggestion_delay is configurable trough JSconfig
var hotcat_suggestion_delay = 100;
var hotcat_old_onsubmit = null;
var hotcat_nosuggestions = false;
// hotcat_nosuggestions is set to true if we don't have XMLHttp! (On IE6, XMLHttp uses
// ActiveX, and the user may deny execution.) If true, no suggestions will ever be
// displayed, and there won't be any checking whether the category exists.
// Lupo, 2008-01-20
var hotcat_modify_blacklist = new Array (
""
) ;
addOnloadHook ( hotcat ) ;
function hotcat () {
if ( hotcat_check_action() ) return ; // Edited page, reloading anyway
// Do not add interface to protected pages, if user has no edit permission
// Also disable it on preview pages: on a preview, we *are* already editing,
// and HotCat must not open the page for editing a second time. Lupo, 2008-02-27
if( wgAction != "view" || document.getElementById('ca-viewsource' ) != null ||
wgNamespaceNumber == -1 || wgNamespaceNumber == 10 )
return;
// If we have no Categories div, then add one
// TheDJ, 2008-02-28
var visible_catlinks = document.getElementById ('mw-normal-catlinks') || getElementsByClassName ( document , "p" , "catlinks" ) [0];
var hidden_catlinks = document.getElementById ('mw-hidden-catlinks');
if ( visible_catlinks == null || typeof( visible_catlinks ) == 'undefined' ) {
d3 = document.createElement ( "div" );
d3.id = "mw-normal-catlinks";
d3.innerHTML = '<a href="/wiki/Special:Categories" title="Special:Categories">Categories</a>: ';
visible_catlinks = d3;
if ( hidden_catlinks ) {
// There are hidden categories.
hidden_catlinks.parentNode.insertBefore( d3, hidden_catlinks );
hidden_catlinks.parentNode.className = "catlinks";
} else {
// This page has no categories at all, lets create a section where we can add them.
var footer = getElementsByClassName ( document , "div" , "printfooter" ) [0];
if( !footer ) return; // We have no idea where we should add this.
d1 = document.createElement ( "div" );
d1.id = "catlinks";
d1.className = "catlinks";
d1.appendChild ( d3 );
footer.parentNode.insertBefore( d1, footer.nextSibling );
}
}
hotcat_modify_existing ( visible_catlinks ) ;
hotcat_append_add_span ( visible_catlinks ) ;
}
function hotcat_append_add_span ( catline ) {
var span_add = document.createElement ( "span" ) ;
var span_sep = document.createTextNode ( " | " ) ;
if ( catline.getElementsByTagName("span")[0] ) catline.appendChild ( span_sep ) ;
catline.appendChild ( span_add ) ;
hotcat_create_span ( span_add ) ;
}
String.prototype.ucFirst = function () {
return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}
function hotcat_is_on_blacklist ( cat_title ) {
if ( !cat_title ) return 0 ;
cat_title = cat_title.ucFirst.replace( /Category:/gi, "" );
for ( var i = 0 ; i < hotcat_modify_blacklist.length ; i++ ) {
if ( cat_title.substr ( 0 , hotcat_modify_blacklist[i].length ) == hotcat_modify_blacklist[i] ) return 1 ;
}
return 0 ;
}
function hotcat_modify_span ( span , i ) {
//var cat_title = span.firstChild.getAttribute ( "title" ) ;
// This fails with MW 1.13alpha if the category is a redlink, because MW 1.13alpha appends
// [[MediaWiki:Red-link-title]] to the category name... it also fails if the category name
// contains "&" (because that is represented by & in the XHTML both in the title and in
// the link's content (innerHTML). Extract the category name from the href instead:
var cat_title = null;
var classes = span.firstChild.getAttribute ('class');
if (classes && classes.search (/\bnew\b/) >= 0) { // href="/w/index.php?title=...&action=edit"
cat_title = hotcatGetParamValue ('title', span.firstChild.href);
} else { // href="/wiki/..."
var re = new RegExp (wgArticlePath.replace (/\$1/, '(.*)'));
var matches = re.exec (span.firstChild.href);
if (matches && matches.length > 1)
cat_title = decodeURIComponent (matches[1]);
else
return;
}
// Strip namespace, replace _ by blank
cat_title = cat_title.substring (cat_title.indexOf (':') + 1).replace (/_/g, ' ');
var sep1 = document.createTextNode ( " " ) ;
var a1 = document.createTextNode ( "(-)" ) ;
var remove_link = document.createElement ( "a" ) ;
// Set the href to a dummy value to make sure we don't move if somehow the onclick handler
// is bypassed.
remove_link.className = "noprint";
remove_link.href = "#catlinks";
remove_link.onclick = hotcat_remove;
remove_link.appendChild ( a1 ) ;
span.appendChild ( sep1 ) ;
span.appendChild ( remove_link ) ;
// Disabled blacklist check TheDJ, 2008-02-28
// if ( hotcat_is_on_blacklist ( cat_title ) ) return ;
var mod_id = "hotcat_modify_" + i ;
var sep2 = document.createTextNode ( " " ) ;
var a2 = document.createTextNode ( "(±)" ) ;
var modify_link = document.createElement ( "a" ) ;
modify_link.id = mod_id ;
modify_link.className = "noprint";
modify_link.href = "javascript:hotcat_modify(\"" + mod_id + "\");" ;
modify_link.appendChild ( a2 ) ;
span.appendChild ( sep2 ) ;
span.appendChild ( modify_link ) ;
span.hotcat_name = cat_title; //Store the extracted category name in our own new property of the span DOM node
}
function hotcat_modify_existing ( catline ) {
var spans = catline.getElementsByTagName ( "span" ) ;
for ( var i = 0 ; i < spans.length ; i++ ) {
hotcat_modify_span ( spans[i] , i ) ;
}
}
function hotcat_getEvt (evt) {
return evt || window.event || window.Event; // Gecko, IE, Netscape
}
function hotcat_evt2node (evt) {
var node = null;
try {
var e = hotcat_getEvt (evt);
node = e.target;
if (!node) node = e.srcElement;
} catch (ex) {
node = null;
}
return node;
}
function hotcat_evtkeys (evt) {
var code = 0;
try {
var e = hotcat_getEvt (evt);
if (typeof(e.ctrlKey) != 'undefined') { // All modern browsers
if (e.ctrlKey) code |= 1;
if (e.shiftKey) code |= 2;
if (e.altKey) code |= 4;
} else if (typeof (e.modifiers) != 'undefined') { // Netscape...
if (e.modifiers & Event.CONTROL_MASK) code |= 1;
if (e.modifiers & Event.SHIFT_MASK) code |= 2;
if (e.modifiers & Event.ALT_MASK) code |= 4;
}
} catch (ex) {
}
return code;
}
function hotcat_killEvt (evt)
{
try {
var e = hotcat_getEvt (evt);
if (typeof (e.preventDefault) != 'undefined') {
e.preventDefault();
e.stopPropagation()
} else
e.cancelBubble = true;
} catch (ex) {
}
}
function hotcat_remove (evt) {
var node = hotcat_evt2node (evt);
if (!node) return false;
// Get the category name from the original link to the category
var cat_title = node.parentNode.hotcat_name;
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
if ((hotcat_evtkeys (evt) & 1) || (hotcat_evtkeys (evt) & 4 )) // CTRL or ALT pressed?
editlk = editlk + '&hotcat_nocommit=1';
hotcat_killEvt (evt);
document.location = editlk + '&hotcat_removecat=' + encodeURIComponent(cat_title) ;
return false;
}
function hotcatGetParamValue(paramName, h) {
if (typeof h == 'undefined' ) { h = document.location.href; }
var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
var m=cmdRe.exec(h);
if (m) {
try {
return decodeURIComponent(m[1]);
} catch (someError) {}
}
return null;
}
// New. Code by Lupo & Superm401, added by Lupo, 2008-02-2007
function hotcat_find_category (wikitext, category)
{
var cat_name = category.replace(/([\\\^\$\.\?\*\+\(\)])/g, "\\$1");
var initial = cat_name.substr (0, 1);
var cat_regex = new RegExp ("\\[\\[\\s*[Cc]ategory\\s*:\\s*"
+ (initial == "\\"
? initial
: "[" + initial.toUpperCase() + initial.toLowerCase() + "]")
+ cat_name.substring (1).replace (/[ _]/g, "[ _]")
+ "\\s*(\\|.*?)?\\]\\]", "g"
);
var result = new Array ();
var curr_match = null;
while ((curr_match = cat_regex.exec (wikitext)) != null) {
result [result.length] = {match : curr_match};
}
return result; // An array containing all matches, with positions, in result[i].match
}
// New. Code by TheDJ, 2008-03-12
function hotcat_find_ins ( wikitext )
{
var re = /\[\[(?:Category):[^\]]+\]\]/ig
var index = -1;
while( re.exec(wikitext) != null ) index = re.lastIndex;
if( index > -1) return index;
//we should try to find interwiki links here, but that's for later.
return -1;
}
// Rewritten (nearly) from scratch. Lupo, 2008-02-27
function hotcat_check_action () {
var ret = 0;
if (wgAction != 'edit' || typeof(document.editform) == "undefined" ) return ret; // Not an edit page, so not our business...
var summary = new Array () ;
var t = document.editform.wpTextbox1.value ;
var prevent_autocommit = 0;
if ( (typeof (hotcat_no_autocommit) != "undefined" && hotcat_no_autocommit)
|| hotcatGetParamValue ('hotcat_nocommit') == '1')
prevent_autocommit = 1;
var cat_rm = hotcatGetParamValue ('hotcat_removecat');
var cat_add = hotcatGetParamValue ('hotcat_newcat');
var comment = hotcatGetParamValue ('hotcat_comment') || "";
var cat_key