LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/widget/songposition.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 (// 使用Wikiplus小工具快速编辑) |
||
(未显示同一用户的16个中间版本) | |||
第1行: | 第1行: | ||
//<nowiki> |
//<nowiki> |
||
// 用于[[Widget:Songposition]],可以使用ES6语法 |
// 用于[[Widget:Songposition]],可以使用ES6语法 |
||
/** |
|||
* @Function: 鼠标移动至歌曲站位图标上方时提示角色姓名 |
|||
* @Dependencies: oojs-ui-core, ext.gadget.site-lib |
|||
* @Author: [[User:Bhsd]] |
|||
*/ |
|||
"use strict"; |
"use strict"; |
||
/*global mw, $*/ |
/* global mw, $ */ |
||
(() => { |
(() => { |
||
const main = () => { |
|||
console.log( 'setInterval: 等待jQuery加载完毕' ); |
|||
const timerStart = Date.now(), |
|||
jqueryTimer = setInterval(() => { |
|||
⚫ | |||
clearInterval(jqueryTimer); |
|||
console.log(`End setInterval: jQuery加载完毕,用时 ${Date.now() - timerStart} ms`); |
|||
mw.widget = mw.widget || {}; |
mw.widget = mw.widget || {}; |
||
if (mw.widget.songposition) { return; } |
if (mw.widget.songposition) { return; } |
||
const targets = ['.member-symbol', '.member-graph'], |
|||
target = targets.join(), |
|||
map = new Map(), |
|||
$body = $( '#bodyContent' ); |
|||
mw.hook( 'wikipage.content' ).add($content => { // 更新图片对应关系 |
|||
if ($content.find( '.member-symbol-image' ).length === 0) { return; } |
|||
console.log('Hook: wikipage.content, 开始更新songposition的图片映射'); |
|||
$content.find( target ).each(function() { map.set(this, $(this).next().find( 'img' )); }); |
|||
}); |
|||
mw.loader.using(['oojs-ui-core', 'ext.gadget.site-lib']).then(() => { |
mw.loader.using(['oojs-ui-core', 'ext.gadget.site-lib']).then(() => { |
||
for (const t of targets) { |
|||
const $label = $('<div>', {html: '<div>'}); |
|||
$body.on('mouseenter', t, function() { |
|||
$label.children( 'div' ).html( map.get(this) ); |
|||
}); |
|||
mw.tipsy($body, t, {id: `${t.slice(1)}-popup`}, $label); |
|||
} |
|||
}); |
}); |
||
mw.widget.songposition = true; |
mw.widget.songposition = true; |
||
} |
}; |
||
⚫ | |||
else { window.addEventListener('jquery', main); } |
|||
}) (); |
}) (); |
||
//</nowiki> |
//</nowiki> |
2022年12月3日 (六) 19:06的最新版本
//<nowiki> // 用于[[Widget:Songposition]],可以使用ES6语法 /** * @Function: 鼠标移动至歌曲站位图标上方时提示角色姓名 * @Dependencies: oojs-ui-core, ext.gadget.site-lib * @Author: [[User:Bhsd]] */ "use strict"; /* global mw, $ */ (() => { const main = () => { mw.widget = mw.widget || {}; if (mw.widget.songposition) { return; } const targets = ['.member-symbol', '.member-graph'], target = targets.join(), map = new Map(), $body = $( '#bodyContent' ); mw.hook( 'wikipage.content' ).add($content => { // 更新图片对应关系 if ($content.find( '.member-symbol-image' ).length === 0) { return; } console.log('Hook: wikipage.content, 开始更新songposition的图片映射'); $content.find( target ).each(function() { map.set(this, $(this).next().find( 'img' )); }); }); mw.loader.using(['oojs-ui-core', 'ext.gadget.site-lib']).then(() => { for (const t of targets) { const $label = $('<div>', {html: '<div>'}); $body.on('mouseenter', t, function() { $label.children( 'div' ).html( map.get(this) ); }); mw.tipsy($body, t, {id: `${t.slice(1)}-popup`}, $label); } }); mw.widget.songposition = true; }; if (window.jQuery) { main(); } else { window.addEventListener('jquery', main); } }) (); //</nowiki> // [[category:jQuery小部件]] {{DEFAULTSORT:Songposition}}