MediaWiki:Gadget-CopyAsChatAlphabet.js:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
var copyOption = false; |
var copyOption = false; |
||
function makeButton() { |
function makeButton() { |
||
var 按钮 = document.createElement('li'); |
var 按钮 = document.createElement('li'); |
||
第23行: | 第24行: | ||
} |
} |
||
var letters = '!bpmwjqxynzDsrHN!bpmwjqxynzDsrHN!bpmwjqxynzDsrHNldtgkh45vF7Bcfualdtgkh45vF7Bcfualdtgkh45vF7BcfuaoeEAYL62T83V1i oeEAYL62T83V1i oeEAYL62T83V1i '; |
|||
⚫ | |||
function 聊天字母化(letter) { |
|||
console.log('哈哈') |
|||
var code = letter.charCodeAt(0) - 0xe020; |
|||
var case = ['^', '', '~'][code / 16 % 3]; |
|||
return case + letters[code]; |
|||
} |
|||
⚫ | |||
var data = e.clipboardData || window.clipboardData; |
|||
if (!data || !copyOption) |
|||
return; |
|||
var text = data.getData('text/plain'); |
|||
data.setData('text/plain', text.replace(/[\ue020-\ue0af]/g, 聊天字母化)); |
|||
}); |
}); |
||
2023年2月9日 (四) 01:40的版本
var copyOption = false;
function makeButton() {
var 按钮 = document.createElement('li');
按钮.classList.add('mw-list-item');
var linkOpen = document.createElement('a');
var linkClose = document.createElement('a');
linkOpen.innerText = '复制聊天字母 ✗';
linkOpen.addEventListener("click", function() {
copyOption = true;
按钮.removeChild(linkOpen);
按钮.appendChild(linkClose);
return false;
});
linkClose.innerText = '复制聊天字母 ✓';
linkClose.addEventListener("click", function() {
copyOption = false;
按钮.removeChild(linkClose);
按钮.appendChild(linkOpen);
return false;
});
按钮.appendChild(linkClose);
return 按钮;
}
var letters = '!bpmwjqxynzDsrHN!bpmwjqxynzDsrHN!bpmwjqxynzDsrHNldtgkh45vF7Bcfualdtgkh45vF7Bcfualdtgkh45vF7BcfuaoeEAYL62T83V1i oeEAYL62T83V1i oeEAYL62T83V1i ';
function 聊天字母化(letter) {
var code = letter.charCodeAt(0) - 0xe020;
var case = ['^', '', '~'][code / 16 % 3];
return case + letters[code];
}
document.getElementById('mw-content-text').addEventListener('copy', function(e) {
var data = e.clipboardData || window.clipboardData;
if (!data || !copyOption)
return;
var text = data.getData('text/plain');
data.setData('text/plain', text.replace(/[\ue020-\ue0af]/g, 聊天字母化));
});
$(function() {
if (!document.querySelector('#p-views #ca-view.selected'))
return; // 仅阅读模式生效
copyOption = true;
var checkbox = document.querySelector('#p-variants ul');
if (checkbox) {
checkbox.appendChild(makeButton());
}
});