imported>=海豚= |
imported>=海豚= |
第1行: |
第1行: |
| /* global mediaWiki */
| | [[ 分类: 工口魔物 娘 图鉴]] |
| (function(mw) {
| |
| if (!String.prototype.includes) String.prototype.includes = function includes(search, start) {
| |
| 'use strict';
| |
| if (typeof start !== 'number') start = 0;
| |
| if (start + search.length > this.length) return false;
| |
| return this.indexOf(search, start) !== -1;
| |
| };
| |
| mw.loader.implement('AnnToolsSendWelcomeMessage', function() {
| |
| var message = '{{Welcome}}',
| |
| errorFun = function errorFun(_, self) {
| |
| unbindFun();
| |
| self.addClass('unsend');
| |
| return false;
| |
| },
| |
| unbindFun = function unbindFun() {
| |
| if ($('#welcomeClear').length > 0) $('#welcomeClear').remove();
| |
| $('#welcomeAsk').append('<span id="welcomeClear">返回</span>');
| |
| $('#welcomeClear').on('click.welcome', function() {
| |
| $('#welcomeAsk').remove();
| |
| });
| |
| };
| |
| if (mw.config.get('wgNamespaceIds').user_talk == mw.config.get('wgNamespaceNumber') && !mw.config.get('wgPageName').includes('/') && mw.config.get('wgEditMessage') == 'creating' && $('#wpTextbox1')[0] && !$('#wpTextbox1').val()) $('#wpTextbox1').val(message);
| |
| | |
| function check(that, onClick) {
| |
| if (!$(that).is('#mw-content-text a.new')) return;
| |
| if (!/(?=title\=user\_talk\:)[^\&]+/i.test(that.href)) return;
| |
| var self = $(that),
| |
| href = self.attr('href'),
| |
| userName = decodeURIComponent(href.match(/(?=user\_talk\:)[^\&]+/i)[0].replace(/user_talk\:/i, ''));
| |
| if (href.includes('User_talk') && href.includes('redlink=1') && href.includes('action=edit') && !userName.includes('/')) {
| |
| self.addClass('sendWelcomeMessageLink unsend nopopus').on('click.sendWelcomeMessage', function() {
| |
| if ($('#welcomeAskFinished')[0]) $('#welcomeClear').click();
| |
| if ($('#welcomeAsk')[0]) {
| |
| self.after('<span class="welcomeAsk">一次只能发送一份欢迎辞哦,不要太贪心了~<span id="welcomeClear2">返回</span></span>');
| |
| $('#welcomeClear2').on('click.welcome', function() {
| |
| $(this).parent().remove();
| |
| });
| |
| return false;
| |
| }
| |
| if (/[&\/]+/.test(userName)) {
| |
| window.open(href, '_blank');
| |
| return errorFun('地址解析出错!\n原地址:' + href + ',解析用户讨论页标题结果:User talk:' + userName, self);
| |
| }
| |
| self.removeClass('unsend').after('<span id="welcomeAsk">你想直接发送欢迎辞还是访问该未创建页面?<span id="welcomeYes">发送欢迎辞</span> · <span id="welcomeNo">访问该页面</span> · <span id="welcomeClear">返回</span></span>');
| |
| $('#welcomeNo').on('click.welcome', function() {
| |
| window.open(href, '_blank');
| |
| });
| |
| $('#welcomeClear').on('click.welcome', function() {
| |
| $('#welcomeAsk').remove();
| |
| });
| |
| $('#welcomeYes').on('click.welcome', function() {
| |
| var api = new mw.Api();
| |
| $('#welcomeAsk').empty().append('正在通信中……');
| |
| api.postWithToken('csrf', {
| |
| 'action': 'edit',
| |
| 'format': 'json',
| |
| 'title': 'User talk:' + userName,
| |
| 'summary': 'Welcome to MoegirlPedia',
| |
| 'text': message,
| |
| 'tags': 'Welcome to MoegirlPedia',
| |
| 'createonly': true
| |
| }).then(function(data) {
| |
| $('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信成功!继续努力哦~</span>');
| |
| console.debug('和萌百服务器通信成功,编辑成功! \n编辑详情:' + JSON.stringify(data).replace(/[{}\"]/g, '').replace(/\:\,/, ',') + '。');
| |
| unbindFun();
| |
| $('#mw-content-text a.new[href="' + href + '"]').removeClass('new sendWelcomeMessageLink unsend').attr('href', '/User_talk:' + userName).off('click.sendWelcomeMessage'); //js<a>对象的href是绝对url……
| |
| }, function(f, s) {
| |
| /*
| |
| * 第一个参数是错误代码,如果是连接错误值为httpss,如果是后端错误值为articleexists等;
| |
| * 第二个参数是错误信息对象,如果是连接错误值为{ xhr: JQueryXHR, exception: String, textStatus: String },如果是后端错误值为后端返回的内容;
| |
| * 如果是后端错误,第三个参数与第二个参数目视一致;
| |
| * 如果是后端错误,第四个参数则是jQueryXHR。
| |
| */
| |
| console.debug('sendWelcomeMessage');
| |
| console.debug.apply(console, arguments);
| |
| if (f === 'internal_api_error_Exception') {
| |
| $('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信成功!继续努力哦~</span>');
| |
| console.debug('和萌百服务器通信成功,编辑成功! \n萌百服务器返回"internal_api_error_Exception",你们都懂的_(:3 」∠ )_ 。');
| |
| unbindFun();
| |
| $('#mw-content-text a.new[href="' + href + '"]').removeClass('new sendWelcomeMessageLink unsend').attr('href', '/User_talk:' + userName).off('click.sendWelcomeMessage'); //js<a>对象的href是绝对url……
| |
| } else if (f === 'articleexists') {
| |
| $('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信成功!该讨论页已经存在,请注意哦~</span>');
| |
| errorFun('和萌百服务器通信成功,但编辑失败!\n编辑详情:' + JSON.stringify(s).replace(/[{}\"]/g, '').replace(/\:\,/g, ','), self);
| |
| unbindFun();
| |
| $('#mw-content-text a.new[href="' + href + '"]').removeClass('new sendWelcomeMessageLink unsend').attr('href', '/User_talk:' + userName).off('click.sendWelcomeMessage'); //js<a>对象的href是绝对url……
| |
| } else {
| |
| var reason = '';
| |
| var object = s.error || s;
| |
| for (var i in object) {
| |
| if (['*', 'xhr'].indexOf(i) !== -1) {
| |
| if (reason) reason += ', ';
| |
| reason += i + ': ' + JSON.stringify(object[i]).replace(/[{}\"]/g, '').replace(/\:\,/g, ',');
| |
| }
| |
| }
| |
| if (typeof f === 'string') reason = f + '(' + reason + '. )';
| |
| else reason += '. ';
| |
| $('#welcomeAsk').empty().append('<span id="welcomeAskFinished">正在通信中……失败!请重试!【 ' + reason + '】</span>');
| |
| errorFun('和萌百服务器通信成功,但编辑失败!\n编辑详情:' + JSON.stringify(s).replace(/[{}\"]/g, '').replace(/\:\,/g, ','), self);
| |
| unbindFun();
| |
| self.addClass('unsend');
| |
| }
| |
| });
| |
| });
| |
| return false;
| |
| });
| |
| if (onClick) self.trigger('click.sendWelcomeMessage');
| |
| return false;
| |
| }
| |
| }
| |
| $(document.body).on('click', function(event) {
| |
| check(event.target, true);
| |
| });
| |
| $('#mw-content-text a.new').each(function() {
| |
| check(this);
| |
| });
| |
| $("<style>#welcomeAsk,.welcomeAsk{border:#bbeeff 1px solid;margin:0 3px 0 7px} #welcomeYes,#welcomeNo,#welcomeClear,#welcomeClear2{cursor:pointer;color:purple}.sendWelcomeMessageLink.unsend:after{content:'S';color:purple;line-height:1;vertical-align:super;font-size:smaller}.sendWelcomeMessageLink{text-decoration:none!important}</style>").appendTo("head");
| |
| });
| |
| })(mediaWiki);
| |
| //</pre>
| |
| //Explanations for this javaScript code in https://zh.moegirl.org/User:AnnAngela/js
| |
| // <pre>
| |
| (function(mw) {
| |
| mw.loader.implement('AnnToolsMWPanel', function($, jQuery) {
| |
| $('#t-upload').after('<li id="t-expandtemplates"><a href="//www.hmoegirl.com/index.php?title=Special:%E5%B1%95%E5%BC%80%E6%A8%A1%E6%9D%BF&wpRemoveComments=1&wpInput={{' + mw.config.get("wgPageName") + '}}">展开模板</a></li><li id="t-Prefixindex"><a href="https://www.hmoegirl.com/index.php?title=Special%3A前缀索引&prefix=' + mw.config.get("wgTitle") + '&namespace=' + mw.config.get("wgNamespaceNumber") + '">前缀页面</a></li><li id="t-pagelog"><a href="//www.hmoegirl.com/index.php?title=Special:%E6%97%A5%E5%BF%97&page=' + mw.config.get("wgPageName") + '">页面日志</a></li><li id="t-replacetext" class="sysop-show"><a href="/Special:替换文本">替换文本</a></li>');
| |
| $('#n-recentchanges').after('<li id="n-log"><a href="/Special:log" title="所有日志">所有日志</a></li><li id="n-ListDuplicatedFiles"><a href="/Special:ListDuplicatedFiles" title="重复文件">重复文件</a></li><style>/* 配合左栏 */#t-expandtemplates, #t-userlog, .ns-2 #t-pagelog, .ns-3 #t-pagelog, .ns--1 #t-pagelog {display:none;}.ns-10 #t-expandtemplates, .ns-2 #t-userlog, .ns-3 #t-userlog {display:list-item!important;}');
| |
| $('#t-log a').text("用户日志");
| |
| });
| |
| })(mediaWiki);
| |
| // </pre>
| |
| $(function(){
| |
| // 小头像放大镜
| |
| setTimeout(function(){
| |
| $('.userlink-avatar').hover(function(){
| |
| var imgUrl = $(this).find('.userlink-avatar-small:first').attr('src')
| |
| var container = $('<div id="userHeadMagnifier" style="display:inline-block; padding:10px; background:white; border:1px black solid; position:absolute; top:-139px; left:-135px;">')
| |
| .append('<img src="' + imgUrl + '" width="128">')
| |
|
| |
| $(this).css('position', 'relative').append(container)
| |
| }, function(){
| |
| $(this).css('position', 'static').find('#userHeadMagnifier').remove()
| |
| })
| |
| }, 1000)
| |
|
| |
| // 阻止复制时添加版权信息
| |
| $('#mw-content-text').off('copy')
| |
|
| |
| // action=purge页面自动点击刷新
| |
| if(! location.search){
| |
| $("#p-cactions ul").append('<li id="btn-renovate"><a title="刷新此页">刷新此页</a></li>')
| |
| $('#btn-renovate').click(function(){
| |
| mw.notify('刷新中...', { type : 'warn' })
| |
| var url = decodeURIComponent(location.href)
| |
| var pageName = url.replace(/^https:\/\/www.hmoegirl.com\/(.+)$/, '$1')
| |
| var api = new mw.Api()
| |
| var deferredTimeoutKey = 0
| |
| $.ajax({
| |
| url: 'https://www.hmoegirl.com/api.php',
| |
| type: 'post',
| |
| timeout: 10000,
| |
| data: {
| |
| "action": "purge",
| |
| "format": "json",
| |
| "titles": pageName
| |
| }
| |
| }).done(function(){
| |
| location.reload(true)
| |
| }).fail(function(e){
| |
| mw.notify('网络错误,刷新失败!', { type : 'error' })
| |
| })
| |
| })
| |
| }
| |
|
| |
| // tab键改为输出2个空格
| |
| $('#wpTextbox1').keydown(function(e){
| |
| if(e.keyCode == 9){
| |
| e.preventDefault()
| |
| var position = this.selectionStart,
| |
| left = this.value.substring(0, position),
| |
| right = this.value.substring(position),
| |
| code = left + ' ' + right
| |
| this.value = code
| |
| this.selectionStart = this.selectionEnd = position + 2
| |
| }
| |
| })
| |
|
| |
| // AJAX编辑预览代替方案(快捷键为:ctrl + shift + s)
| |
| if(/((?!\.css|\.js|模块|module).+)action=(edit|submit)/.test(location.href)){
| |
| setTimeout(function(){
| |
| $('#wikiEditor-ui-toolbar .tabs').append($('<span id="edit-ajaxPreviewBtn" class="tab"><a href="#" role="button" aria-pressed="false">预览</a></span>'))
| |
| $('#edit-ajaxPreviewBtn').click(foo)
| |
| }, 3000)
| |
| var removeBtn = $('<div id="edit-ajaxPreviewRm" style="width:43px; height:30px; text-align:center; line-height:30px; color:black; font-size:26px; background:white; box-shadow:0 0 5px black; opacity:0.8; position:fixed; top:20px; right:0; cursor:pointer; display:none; z-index:1001;">×</div>')
| |
| .click(function(){
| |
| viewHide()
| |
| })
| |
| $('body').append(removeBtn)
| |
|
| |
| var saveBtn = $('<div id="edit-ajaxPreviewSave" style="width:43px; height:30px; text-align:center; line-height:30px; color:black; font-size:26px; background:white; box-shadow:0 0 5px black; opacity:0.8; position:fixed; top:73px; right:0; cursor:pointer; display:none; z-index:1001;">√</div>')
| |
| .click(function(){
| |
| $('#wpSave').click()
| |
| })
| |
| $('body').append(saveBtn)
| |
| | |
| var requestTimeoutKey = 0,
| |
| deferred = null
| |
| function viewHide(){
| |
| deferred && deferred.abort()
| |
| clearTimeout(requestTimeoutKey)
| |
| $('#edit-ajaxPreview').remove()
| |
| $('#edit-ajaxPreviewRm').hide()
| |
| $('#edit-ajaxPreviewSave').hide()
| |
| $('body').css('overflow', 'visible')
| |
| }
| |
|
| |
| $(window).keydown(function(e){
| |
| if(e.ctrlKey && e.keyCode == 83){
| |
| if($('#edit-ajaxPreview').length){
| |
| viewHide()
| |
| }else{
| |
| foo(e)
| |
| }
| |
| }
| |
| })
| |
|
| |
| var api = new mw.Api()
| |
| function foo(e){
| |
| var previewElement = $('<div id="edit-ajaxPreview" style="width:90%; min-width:800px; height:90%; min-height:400px; padding:15px; background:white; box-shadow:0 0 15px #666; overflow:auto; position:fixed; margin:auto; top:0; left:0; right:0; bottom:0; z-index:1000;">').append('<span id="edit-ajaxPreview-LoadingMsg" style="font-size:30px; position:fixed; top:50%; left:50%; transform:translate(-50%, -50%);">获取预览中...</span>')
| |
| $('body').append(previewElement)
| |
| | |
| var wikiText = $('#wpTextbox1').val(),
| |
| titleName = decodeURIComponent(location.href.replace(/^.+[?&]title=([^&]+)&.+$/, '$1'))
| |
| $('#edit-ajaxPreviewRm').show()
| |
| $('#edit-ajaxPreviewSave').show()
| |
| $('body').css('overflow', 'hidden')
| |
| deferred = api.post({
| |
| "action": "parse",
| |
| "format": "json",
| |
| "text": wikiText,
| |
| "title": titleName,
| |
| "contentmodel": "wikitext"
| |
| }).done(function(data){
| |
| $('#edit-ajaxPreview').html($(data.parse.text['*']).addClass('mw-body-content'))
| |
| })
| |
| requestTimeoutKey = setTimeout(function(){
| |
| if(deferred.state() != 'resolved'){
| |
| viewHide()
| |
| foo(e)
| |
| }
| |
| }, 8000)
| |
| return false
| |
| }
| |
| }
| |
|
| |
| // ctrl + alt快速添加变量命名空间
| |
| if (mw.config.values.wgAction == "edit" || mw.config.values.wgAction == "submit"){
| |
| var editor = $('#wpTextbox1')
| |
| var title = mw.config.values.wgTitle.replace(/./, function(s){
| |
| return s.toLowerCase()
| |
| })
| |
| editor.keydown(function(e){
| |
| if(e.ctrlKey && e.altKey){
| |
| editor.val(editor.val().replace(/(\{\{#var(define|):)([^\|\}]+)/g, function(s, s1, s2, s3){
| |
| if(!new RegExp('^' + title + '\\.').test(s3)){
| |
| if(['num', 'key', 'value', 'time', 'times'].includes(s3)){ return s }
| |
| return s1 + title + '.' + s3
| |
| }
| |
|
| |
| return s
| |
| }))
| |
|
| |
| mw.notify('已添加变量命名空间。')
| |
| }
| |
| })
| |
| }
| |
| })
| |
| | |
| // $.getScript("/User:Imbushuo/MonacoEditor/MediaWikiTokenizer.js?action=raw&ctype=text/javascript",
| |
| // function (data, textStatus, jqxhr) {
| |
| // $.getScript("/User:imbushuo/MediaWikiLint.js?action=raw&ctype=text/javascript",
| |
| // function (data, textStatus, jqxhr) {
| |
| // // Loader for Monaco editor
| |
| // mw.loader.load('https://zh.moegirl.org/User:Imbushuo/MonacoEditor.js?action=raw&ctype=text/javascript');
| |
| // });
| |
| // });
| |
| | |
| | |
| // 搜索引擎代替方案
| |
| /*
| |
| $(function(){
| |
| var input = $('#searchInput').attr('placeholder', '搜索萌 娘 百科')
| |
| $('#searchButton').off().on('click', function() {
| |
| var keyword = input.val();
| |
| if (!keyword) window.alert('请输入关键词后再行搜索!');
| |
| else {
| |
| var self = $(this),
| |
| check_url = 'https://hmoegirl.com/' + keyword,
| |
| open_url = 'https://www.bing.com/search?q=' + encodeURIComponent(keyword) + '+site%3Azh.hmoegirl.com&ie=UTF-8';
| |
| self[0].disabled = true;
| |
| self.data({
| |
| 'background-image': self.css('background-image'),
| |
| 'background-size': self.css('background-size')
| |
| });
| |
| self.css({
| |
| 'background-image': 'url(https://static.mengniang.org/common/d/d1/Windows_10_loading.gif)',
| |
| 'background-size': '80%'
| |
| });
| |
| $.ajax({
| |
| url: check_url,
| |
| type: 'HEAD',
| |
| success: function(_, __, response) {
| |
| if (response.status < 400) location.href = check_url;
| |
| else this.error();
| |
| },
| |
| error: function() {
| |
| location.href = open_url
| |
| },
| |
| complete: function() {
| |
| self[0].disabled = false;
| |
| self.css(self.data());
| |
| }
| |
| });
| |
| }
| |
| return false;
| |
| });
| |
| })
| |
| */
| |
| mw.loader.load('MediaWiki:Gadget-DotsSyntaxHighlighter.js');
| |
| mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');
| |
| /*
| |
| 这是一个保存编辑内容的小插件,载入后将在“显示更改”按钮后生成一个“还原备份”按钮。
| |
| 萌百本身有一个缓存编辑的内容的插件,但是我用得感觉很迷,曾经两次在开了那个插件的情况下提交编辑后发生网络错误,
| |
| 然而再次回到编辑页面后却无法还原,不知道是有Bug还是我没用好。
| |
|
| |
| 这个插件将在点击“提交编辑、显示预览、显示更改”中任意一个按钮时备份当前的编辑。当存在备份时,“还原备份”按钮变为可以点击。
| |
| 备份会保存7天,7天后自动清除。
| |
| */
| |
| $(function(){
| |
| if(! /action=(edit|submit)/.test(location.href)){ return }
| |
| | |
| var editBox = $('#wpTextbox1'),
| |
| btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget'),
| |
| title = decodeURIComponent(location.search.match(/title=([^&]+)/)[1]),
| |
| backupList = JSON.parse(localStorage.getItem('Moegirl-koharubiyori-editBackup') || '{}')
| |
|
| |
| $.each(backupList, function(key, val){
| |
| var time = new Date().getTime()
| |
| if(val.expires < time){
| |
| delete backupList[key]
| |
| }
| |
| })
| |
| | |
| setTimeout(function(){
| |
| var backup = backupList[title]
| |
| if(backup){
| |
| var btn = $('<span class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget"><input type="button" value="还原备份" class="oo-ui-inputWidget-input oo-ui-buttonElement-button" /></span>')
| |
| .click(function(){
| |
| editBox.val(backup.content)
| |
| mw.notify('已还原备份!', { type: 'warn' })
| |
| })
| |
| }else{
| |
| var btn = $('<span class="oo-ui-widget oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget oo-ui-widget-disabled"><input type="button" value="还原备份" class="oo-ui-inputWidget-input oo-ui-buttonElement-button" disabled /></span>')
| |
| }
| |
| $('#wpDiffWidget').after(btn)
| |
| })
| |
| | |
| btns.mousedown(function(e){
| |
| var content = editBox.val()
| |
| var expire = new Date().getTime() + 1000 * 60 * 60 * 24 * 7
| |
| backupList[title] = {
| |
| expires : expire,
| |
| content : content
| |
| }
| |
| localStorage.setItem('Moegirl-koharubiyori-editBackup', JSON.stringify(backupList))
| |
| })
| |
| })
| |