User:संतोष दहिवळ/chick.js

/* Script: 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  * In sync with version: http://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&oldid=19600669  * Major changes:  *   - 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  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. *  - Postfix blacklisting in addition to prefix blacklisting. * User:TheDJ 2009-04-18   */

var pendch_http; var pendch_enabled; var pendch_num_pages; var pendch_refresh; var pendch_num_idle_req; var pendch_curr_idle_req; var pendch_diffonly;

var pendch_str_no_ajax = "There seems to be a problem using the PendingChanges script. Your browser is not supported. God Bless!"; var pendch_str_box_title = "Pending changes"; var pendch_str_box_title_updating = "Pending ch. (upd.)"; var pendch_str_box_title_failed = "Pending changes (update failed)"; var pendch_str_enable = "Enable this box"; var pendch_str_disable = "Disable this box";

$( pendch_init ); /* initalise */ function pendch_init { if (window.location.toString.search(/diffonly=1/) != -1) { var currURL = window.location.toString; var newURL=currURL.replace(/diffonly=1/,diffonly=0); console.log(document.getElementById("difference").innerHTML); if (document.getElementById("difference").innerHTML.search(/Show page below diff/) == -1) { document.getElementById("difference").innerHTML += ' (Show page below diff)'; } }  // allow user settings through if (pendch_enabled == null) { pendch_enabled = false; } if (pendch_num_pages == null) { pendch_num_pages = 10; } if (pendch_refresh == null) { pendch_refresh = 10; } if (pendch_num_idle_req == null) { pendch_num_idle_req = 60; } if(pendch_diffonly == null) { pendch_diffonly = 1; }

// A few limits to be nice to the servers if (pendch_num_pages > 50) { pendch_num_pages = 50; } if (pendch_num_pages < 1) { pendch_num_pages = 1; } if (pendch_refresh < 2) { pendch_refresh = 2; } if (pendch_num_idle_req > 1000) { pendch_num_idle_req = 1000; } if (pendch_num_idle_req < 5) { pendch_num_idle_req = 5; }

// get our cookie if (document.cookie.length > 0) { var c_start = document.cookie.indexOf("pendch_show_box="); if (c_start != -1) { c_start = c_start + 16; var c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) { c_end = document.cookie.length; }     if (document.cookie.substring(c_start, c_end) == "yes") { pendch_enabled = true; } else { pendch_enabled = false; }   }   }  // Either make a request or show nothing pendch_curr_idle_req = 0; if (pendch_enabled == true) { pendch_ajax_request; } else { pendch_draw_disabled_box; } } /* init ajax */ function pendch_create_request { try { pendch_http = new XMLHttpRequest; } catch (e) { try { pendch_http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { pendch_http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { return false; }   }  }  pendch_http.onreadystatechange = function { if(pendch_http.readyState == 4) pendch_ajax_response; } return true; } /* make a request */ function pendch_ajax_request { // if we have done too many requests, disable the box pendch_curr_idle_req++; if (pendch_curr_idle_req > pendch_num_idle_req) { pendch_disable_box; }

// check we are enabled if (pendch_enabled == false) return;

// firstly, inform the user var cur_box = document.getElementById('p-pendingchanges'); if (cur_box != null) { cur_box.firstChild.firstChild.data = pendch_str_box_title_updating; }

if (pendch_create_request == false) { if (cur_box != null) { cur_box.firstChild.firstChild.data = pendch_str_box_title_failed; } else { alert (pendch_str_no_ajax); } }  // Get the current time var dateobj = new Date; var now = Math.floor(dateobj.getTime / 1000.0);

// Go back 5 mins in time //now -= (60 * 5);

// Then make the request pendch_http.open("GET", "/w/api.php?action=query&format=xml&list=oldreviewedpages&ornamespace=0|4&orlimit=" + pendch_num_pages, true); pendch_http.send(null); }

function pendch_draw_disabled_box { if (skin == 'vector') { pendch_draw_disabled_box_vector; } else { pendch_draw_disabled_box_monobook; } }

function pendch_ajax_response { if (skin == 'vector') { pendch_ajax_response_vector; } else { pendch_ajax_response_monobook; }

// and do it again in 5 secs setTimeout("pendch_ajax_request", pendch_refresh * 1000); }

function pendch_disable_box { pendch_enabled = false; pendch_draw_disabled_box; document.cookie = "pendch_show_box=no; path=/"; } function pendch_enable_box { pendch_enabled = true; pendch_curr_idle_req = 0; document.cookie = "pendch_show_box=yes; path=/"; pendch_ajax_request; }

/* Draw disabled (monobook) */ function pendch_draw_disabled_box_monobook { // Container div var link_div = document.createElement('div'); link_div.className = 'pBody'; var div = document.createElement('div'); div.setAttribute('id', 'p-pendingchanges'); div.className = 'portlet'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode(pendch_str_box_title)); div.appendChild(heading); div.appendChild(link_div); // enable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; var a = document.createElement('a'); a.appendChild(document.createTextNode(pendch_str_enable)); a.onclick = pendch_enable_box; p.appendChild(a); link_div.appendChild(p); // now replace the div var old_div = document.getElementById('p-pendingchanges'); var side_col = document.getElementById('column-one'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-search'); side_col.insertBefore(div, node); } }

/* Draw response (monobook) */ function pendch_ajax_response_monobook {

var items = pendch_http.responseXML.getElementsByTagName('p');

// create the div that holds all the pending changes links var link_div = document.createElement('div'); link_div.className = 'pBody'; var list = document.createElement('ul'); link_div.appendChild(list); // populate the list with 10 links. for (var i = 0; i < items.length; i++) { var item_name = items[i].getAttribute('title'); var old_id = items[i].getAttribute('stable_revid'); var under_review = items[i].getAttribute('under_review'); item_name = item_name.replace(/&/, "%26"); var item_url = 'http://en.wikipedia.org/w/index.php?title=' + item_name + '&diff=cur&oldid=' + old_id + '&diffonly=' + pendch_diffonly; a = document.createElement('a'); a.setAttribute('href', item_url); a.appendChild(document.createTextNode(item_name));

var li = document.createElement('li'); li.appendChild(a); if (under_review == "1") { li.setAttribute('style','background-color: yellow;'); }   list.appendChild(li); } // Container div var div = document.createElement('div'); div.setAttribute('id', 'p-pendingchanges'); div.className = 'portlet'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode(pendch_str_box_title)); div.appendChild(heading); div.appendChild(link_div); // disable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; p.style.textAlign = 'right'; a = document.createElement('a'); a.appendChild(document.createTextNode(pendch_str_disable)); a.onclick = pendch_disable_box; p.appendChild(a); link_div.appendChild(p); // now replace the div var old_div = document.getElementById('p-pendingchanges'); var side_col = document.getElementById('column-one'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-search'); side_col.insertBefore(div, node); } }

/* Draw disabled box (vector skin) */ function pendch_draw_disabled_box_vector { // Container div var link_div = document.createElement('div'); link_div.className = 'body'; link_div.style.display = "block"; var div = document.createElement('div'); div.setAttribute('id', 'p-pendingchanges'); div.className = 'portal collapsed'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode(pendch_str_box_title)); div.appendChild(heading); div.appendChild(link_div); // enable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; var a = document.createElement('a'); a.appendChild(document.createTextNode(pendch_str_enable)); a.onclick = pendch_enable_box; p.appendChild(a); // add later // now replace the div var old_div = document.getElementById('p-pendingchanges'); var side_col = document.getElementById('mw-panel'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-interaction'); side_col.insertBefore(div, node); }

if( typeof $ != 'undefined' && wgVectorEnabledModules.collapsiblenav ) { $('#p-pendingchanges > h5').keydown( function( event ) {     if ( event.which == 13 /* Enter */ || event.which == 32 /* Space */ ) {        pendch_toggle( $(this) );      }    } ) .mousedown( function {     pendch_toggle( $(this) );      $(this).blur;        return false;    } ); } else { link_div.appendChild(p); } }

/* Draw response (vector skin) */ function pendch_ajax_response_vector { var items = pendch_http.responseXML.getElementsByTagName('p'); // create the div that holds all the pending changes links var link_div = document.createElement('div'); link_div.className = 'body'; link_div.style.display = "block"; var list = document.createElement('ul'); link_div.appendChild(list); // populate the list with 10 links. for (var i = 0; i < items.length; i++) { var item_name = items[i].getAttribute('title'); var old_id = items[i].getAttribute('stable_revid'); var under_review = items[i].getAttribute('under_review');

item_name = item_name.replace(/&/, "%26"); var item_url = 'http://en.wikipedia.org/w/index.php?title=' + item_name + '&diff=cur&oldid=' + old_id + '&diffonly=' + pendch_diffonly; a = document.createElement('a'); a.setAttribute('href', item_url); //a.style.fontSize = 'x-small'; a.appendChild(document.createTextNode(item_name)); var li = document.createElement('li'); li.appendChild(a); if(under_review == "1") { li.setAttribute('style','background-color: yellow;'); }   list.appendChild(li); } // Container div var div = document.createElement('div'); div.setAttribute('id', 'p-pendingchanges'); div.className = 'portal expanded'; var heading = document.createElement('h5'); heading.appendChild(document.createTextNode(pendch_str_box_title)); div.appendChild(heading); div.appendChild(link_div);

// disable link var p = document.createElement('p'); p.style.fontSize = 'x-small'; p.style.margin = '0px'; p.style.textAlign = 'left'; a = document.createElement('a'); a.appendChild(document.createTextNode(pendch_str_disable)); a.onclick = pendch_disable_box; p.appendChild(a); // add later

// now replace the div var old_div = document.getElementById('p-pendingchanges'); var side_col = document.getElementById('mw-panel'); if (old_div != null) { side_col.replaceChild(div, old_div); } else { var node = document.getElementById('p-interaction'); side_col.insertBefore(div, node); }

if( typeof $ != 'undefined' && wgVectorEnabledModules.collapsiblenav ) { $('#p-pendingchanges > h5').keydown( function( event ) {     if ( event.which == 13 /* Enter */ || event.which == 32 /* Space */ ) {        pendch_toggle( $(this) );      }    } ) .mousedown( function {     pendch_toggle( $(this) );      $(this).blur;        return false;    } ); } else { link_div.appendChild(p); } }

function pendch_toggle( $element ) { $.cookie( 'vector-nav-' + $element.parent.attr( 'id' ), $element.parent.is( '.collapsed' ) ); if( $element.parent.is('.collapsed') ) { pendch_enable_box; } else { pendch_disable_box; } $element .parent .toggleClass( 'expanded' ) .toggleClass( 'collapsed' ) .find( 'div.body' ) .slideToggle( 'fast' ); }