利用者:FlatLanguage/EasyAttribution-mdwiki.js
表示
お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。
多くの Windows や Linux のブラウザ
- Ctrl を押しながら F5 を押す。
Mac における Safari
Mac における Chrome や Firefox
- ⌘ Cmd と ⇧ Shift を押しながら R を押す。
詳細についてはWikipedia:キャッシュを消すをご覧ください。
//[[ja:User:Frozen-mikan/retrieveSigning.js]]を改変
jQuery(function() {
if ( mw.config.get('wgAction') == 'edit' ) return;
if (!(document.location.href).includes('oldid') && !(document.location.href).includes('diff')) return;
var revisionid = mw.config.get('wgRevisionId');
var oldid = mw.config.get('wgDiffOldId');
var newid = mw.config.get('wgDiffNewId');
var pageid = mw.config.get('wgArticleId');
var pagetitle;
var editor;
var EditTimeStamp;
var parentid;
var funcs = {};
function createElement(name, attr, inner) {
if (!name) return null;
var element = document.createElement(name);
// attr
for (key in attr) {
if (key == 'style') {
for (styleKey in attr[key]) {
element[key][styleKey] = attr[key][styleKey];
}
} else {
element.setAttribute(key, attr[key]);
}
}
// inner
if (typeof inner == 'undefined') return element;
for (var i=0; i<inner.length; ++i) {
if (typeof inner[i] == 'string') {
element.appendChild(document.createTextNode(inner[i]));
} else {
element.appendChild(inner[i]);
}
}
return element;
}
var contentSub = document.getElementById('contentSub');
if (!contentSub ||
!contentSub.parentNode ||
!contentSub.parentNode.insertBefore
) {
return;
}
/*
*
*/
var parts = [ { 'id' : 'rev_title', 'label': 'ページと固定リンク', 'func':
function () {
var date = EditTimeStamp;
var text = '[[mdwiki' + ':Special:Redirect/page/' + pageid + '|mdwiki:' + pagetitle + ']]の';
text += '[[mdwiki' + ':Special:Permalink/' + revisionid + '|' + date + ']]の版';
return text;
}}, { 'id' : 'rev_user', 'label': '編集者と固定リンク', 'func':
function () {
var date = EditTimeStamp;
var text = '[[mdwiki' + ':Special:Contributions/' + editor + '|' + editor + ']]';
text += ' ([[mdwiki' + ':User_talk:' + editor + '|talk]]) による';
text += '[[mdwiki' + ':Special:Permalink/' + revisionid + '|' + date + ']]の版';
return text;
}}, { 'id' : 'sp_diff', 'label': '差分', 'func':
function () {
text = '[[mdwiki' + ':Special:Diff';
if (oldid && parentid != oldid) {
text += '/' + oldid;
}
if (newid) {
text += '/' + newid;
} else {
text += '/' + revisionid;
}
text += ']]';
return text;
}}];
(function() {
var _br = function() { return createElement('br'); };
var _radio = function(value, checked) {
var attr = {'type': 'radio', 'name': 'r1', 'value': value};
if (checked) attr.checked = 'checked';
return createElement('input', attr); };
var _label = function(text, element) {
var inner = (element.type == 'radio') ? [element, text] : [text, element];
return createElement('label', {}, inner); };
var button = createElement('button', {'type': 'button'}, ['取得']);
var radioItems = [];
var firstItem = true;
for (var i = 0; i < parts.length; ++i) (function(part){
funcs[part.id] = part.func;
radioItems.push(_label(part.label, _radio(part.id, firstItem)));
firstItem = false;
})(parts[i]);
var output = createElement('input', {'type': 'text', 'size': '80'}, []);
var outputLabel = _label('取得結果', output);
var formItems = [button].concat(radioItems, _br(), outputLabel);
var form = createElement('form', {'id': 'get_revision', 'class': 'noprint'}, formItems);
var cacheText = {};
function displayText() {
if (!button.disabled) return;
var val = checkedValue('r1');
var text = cacheText[val];
if (typeof text == 'undefined') {
var func = funcs[val];
if (typeof func == 'function') {
cacheText[val] = text = func();
} else {
if (window.console) {
console.log('func[\'' + val + '\']: ' + func);
}
}
}
output.value = text;
output.select();
}
function checkedValue(name) {
var buttons = form[name];
for (var i = 0; i < buttons.length; ++i) {
if (buttons[i].checked) return buttons[i].value;
}
}
jQuery( button ).click(function(){
button.disabled = true;
mw.loader.using('mediawiki.api', function() {
new mw.Api().get({
action: 'query',
format: 'json',
formatversion: 2,
prop: 'revisions',
rvprop: 'ids|timestamp|user',
revids: revisionid
}).then(function (obj) {
pagetitle = obj.query.pages[0].title;
editor = obj.query.pages[0].revisions[0].user;
EditTimeStamp = obj.query.pages[0].revisions[0].timestamp;
parentid = obj.query.pages[0].revisions[0].parentid;
displayText();
});
});
});
for (var i =0; i < radioItems.length; ++i) (function(radio) {
jQuery( radio ).click(function(e) {
var src = e.target || e.srcElement;
if (src && src.type == 'radio') displayText();
});
})(radioItems[i]);
contentSub.parentNode.insertBefore(form, contentSub.nextSibling);
})();
});