Difference between revisions of "User:Shine/valve.js"

From Team Fortress Wiki
Jump to: navigation, search
m
m
 
(5 intermediate revisions by the same user not shown)
Line 31: Line 31:
 
//
 
//
  
// This defines some control-key shortcuts you can use in text fields.
+
function gid(i) {
// IE not supported.  See talk page for documentation.
+
    return document.getElementById(i);
// by Greg Ubben
+
}
+
function replaceRecentChangesLink(){
// Add some control hotkeys for easily entering right-arrows () and other
+
     if(gid('n-recentchanges')) {
// characters and phrases in the edit summary, edit box, or other text fields.
+
         var a = gid('n-recentchanges').getElementsByTagName('a');
// hotkeys[] can be defined to augment the defaults. Type Ctrl-? to list all.
+
         for(i in a) {
+
             a[i].href = '/w/index.php?title=Special:RecentChanges&hidebots=0';
function hotkey(e) {
 
     if (e && e.ctrlKey && hotkeys[String.fromCharCode( e.charCode )])
 
    {
 
         var newtxt = hotkeys[String.fromCharCode( e.charCode )];
 
        var before = this.value.slice( 0, this.selectionStart );
 
        var after  = this.value.slice( this.selectionEnd );
 
         var scroll = this.scrollTop;
 
 
        if (newtxt == "MENU") {        // type Ctrl-? for a list
 
            var menu = "";
 
            for (var key in hotkeys) {
 
                var name  = key.toUpperCase().replace(",", "<").replace(".", ">");
 
                var value = hotkeys[key].replace(/\n/g, "•").slice(0,40);
 
                if (value && value != newtxt)
 
                    menu += "\u200E" + name + " \t" + value + "\n";
 
             }
 
            alert( menu );
 
            return false;
 
        }
 
        //  hack to not override Ctrl-F, Ctrl-T, etc. in main text area
 
        //
 
        if (newtxt.search(/\[\[WP:|\bfix/i) >= 0 && this.id == "wpTextbox1") {
 
            return true;
 
        }
 
        if (newtxt.search(/^\[*\w./) >= 0 && this.id != "wpTextbox1") {
 
            if (before.search(/[^\s;,]$/) >= 0)  before += "; ";
 
            if  (after.search(/^[^\s;,]/) >= 0)  newtxt += "; ";
 
 
         }
 
         }
        this.value = before + newtxt + after;
 
        this.selectionStart = this.selectionEnd = before.length + newtxt.length;
 
        this.scrollTop = scroll;      // don't lose our position
 
        return false;
 
 
     }
 
     }
    return true;
 
 
}
 
}
+
addOnloadHook(replaceRecentChangesLink);
addOnloadHook( function()
+
 
{
+
//
    var defaultCtrl = {
 
        "U" : "Ü",                  // Ctrl U  umlaut
 
    };
 
    var fields = { wpSummary:0, wpTextbox1:0, wpReason:0, wpUploadDescription:0 };
 
 
    if (wgAction != "view" || wgCanonicalSpecialPageName)
 
    {
 
        if (typeof(hotkeys) == 'undefined')  hotkeys = {};
 
        for (var key in defaultCtrl) {
 
            if (hotkeys[key] == null)
 
                hotkeys[key] = defaultCtrl[key];
 
        }
 
        for (var field in fields) {
 
            var f = document.getElementById(field);
 
            if (f)  f.onkeypress = hotkey;
 
        }
 
    }
 
});
 

Latest revision as of 07:21, 26 August 2010

// addPurge
addOnloadHook(function () {
    var hist; var url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                   'Purge', 'ca-purge', 'Purge server cache for this page', '0');
});

//

// Adds a "Replace" tab which pops up two prompt boxes; one for a regexp and one for a replacement
function wpTextboxReplace()
{
    var s = prompt("Search regexp:");
    if(s){
        var r = prompt("Replace /"+s+"/ with:");
        if(!r && r != '') return;
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "mg"), r);
    }
}
addOnloadHook(function () {
    if (document.forms.editform) {
        addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
                       'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
    }
});
 
//

function gid(i) {
    return document.getElementById(i);
}
function replaceRecentChangesLink(){
    if(gid('n-recentchanges')) {
        var a = gid('n-recentchanges').getElementsByTagName('a');
        for(i in a) {
            a[i].href = '/w/index.php?title=Special:RecentChanges&hidebots=0';
        }
    }
}
addOnloadHook(replaceRecentChangesLink);

//