מדיה ויקי:Gadget-browsertab.js: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
אין תקציר עריכה |
||
| שורה 1: | שורה 1: | ||
/* | |||
This gadget shortens the tab browser title. | |||
For example, | |||
"(1) אורי צבי גרינברג - הבדלי גרסאות" | |||
יהפוך להיות | |||
"(1) =אורי צבי גרינברג — השוואה" | |||
To understand RTL, the translated result is | |||
"(1) =PageName — diff". | |||
The structure of the new title includes: | |||
1) Browser number data, as "(1)", if existed in the original title. | |||
2) Action symbol, "=" for diff, "^" for editing, "!" for history, nothing for reading. | |||
3) Page name with shortened namespace. | |||
4) Text " — " | |||
5) Action full name, like "ויקיפדיה" for reading, "השוואה", "עריכה", "היסטוריה". | |||
There is no change for two different pages comparing. | |||
*/ | |||
$(function () { | $(function () { | ||
// data about action symbols and names | // data about action symbols and names | ||
| שורה 16: | שורה 32: | ||
format: "json" | format: "json" | ||
}; | }; | ||
// find current action | // find current action | ||
var action, letter, actionname; | |||
if ($('.difference-title').length > 0) | if ($('.difference-title').length > 0) | ||
action = 'diff'; | action = 'diff'; | ||
else if ($('#contentSub').length > 0 && $('#contentSub').text().indexOf('הבדלים בין דפים') !== -1) | else if ($('#contentSub').length > 0 && $('#contentSub').text().indexOf('הבדלים בין דפים') !== -1) | ||
// different pages comparing, do not | // different pages comparing, do not touch | ||
return; | return; | ||
else | else | ||
| שורה 29: | שורה 45: | ||
return; | return; | ||
else | else | ||
[letter, | [letter, actionname] = letters[action]; | ||
// get browser number data at title start | // get browser number data at title start | ||
var oldtext = $(document).prop('title'); | var oldtext = $(document).prop('title'); | ||
| שורה 40: | שורה 56: | ||
// set the new title | // set the new title | ||
$(document) | $(document) | ||
.prop('title', partext + letter + data.expandtemplates.wikitext + ' — ' + | .prop('title', partext + letter + data.expandtemplates.wikitext + ' — ' + actionname); | ||
}); | }); | ||
}); | }); | ||
// dependencies=mediawiki.api | |||
גרסה מ־14:01, 29 בנובמבר 2021
/*
This gadget shortens the tab browser title.
For example,
"(1) אורי צבי גרינברג - הבדלי גרסאות"
יהפוך להיות
"(1) =אורי צבי גרינברג — השוואה"
To understand RTL, the translated result is
"(1) =PageName — diff".
The structure of the new title includes:
1) Browser number data, as "(1)", if existed in the original title.
2) Action symbol, "=" for diff, "^" for editing, "!" for history, nothing for reading.
3) Page name with shortened namespace.
4) Text " — "
5) Action full name, like "ויקיפדיה" for reading, "השוואה", "עריכה", "היסטוריה".
There is no change for two different pages comparing.
*/
$(function () {
// data about action symbols and names
var letters = {
view: ['', 'ויקיפדיה'],
purge: ['', 'ויקיפדיה'],
submit: ['^', 'עריכה'],
edit: ['^', 'עריכה'],
history: ['!', 'היסטוריה'],
diff: ['=', 'השוואה']
};
// api parameters
var params = {
action: "expandtemplates",
text: "{{קיצור מרחב השם|" + mw.config.get('wgPageName').replaceAll('_', ' ') + "}}",
prop: "wikitext",
format: "json"
};
// find current action
var action, letter, actionname;
if ($('.difference-title').length > 0)
action = 'diff';
else if ($('#contentSub').length > 0 && $('#contentSub').text().indexOf('הבדלים בין דפים') !== -1)
// different pages comparing, do not touch
return;
else
action = mw.config.get('wgAction');
// unknown action
if (letters[action] == null)
return;
else
[letter, actionname] = letters[action];
// get browser number data at title start
var oldtext = $(document).prop('title');
var par = oldtext.match(/\([^\)]*\)/g);
var partext = par == null || oldtext.indexOf(par[0]) != 0 ? '' : par[0] + ' ';
// get the short name
var api = new mw.Api();
api.get(params)
.done(function(data) {
// set the new title
$(document)
.prop('title', partext + letter + data.expandtemplates.wikitext + ' — ' + actionname);
});
});
// dependencies=mediawiki.api