User:Liangent/Scripts/AutoTrigger.js
外观
< User:Liangent | Scripts
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
(function($, mw) { $.getScript( '//raw.githubusercontent.com/eduardolundgren/jquery-simulate/master/jquery.simulate.js', function() { mw.loader.using(['mediawiki.user', 'mediawiki.util'], function() { $(function() {
// We use the watchlist token, which is considered safe to expose in request URL by users.
var token = mw.user.sessionId();
if (mw.util.getParamValue('autotrigger_token') == token) {
var element = mw.util.getParamValue('autotrigger_element'), $element = $(element);
var event = mw.util.getParamValue('autotrigger_event') || 'click';
mw.util.jsMessage('"' + event + '" event has been triggered on "' + element + '" element'
+ ($element.length > 1 ? 's' : '') + '.');
$element.simulate(event);
}
$('.autotrigger a').each(function() {
var element = $(this);
var href = element.attr('href');
var atelement = mw.util.getParamValue('autotrigger_element', href);
var atevent = mw.util.getParamValue('autotrigger_event', href) || 'click';
element.append($('<abbr style="font-weight: bold; font-size: large; color: red;">⚠</abbr>').attr(
'title', 'Following this link will trigger "' + atevent
+ '" event on "' + atelement + '" element(s) on the next page.'
));
href += href.indexOf('?') == -1 ? '?' : '&';
href += 'autotrigger_token=' + encodeURIComponent(token);
element.attr('href', href);
});
}); }); }); })(jQuery, mediaWiki);