[]
は削除されるscript.jsscrapbox.PopupMenu.addButton({
title: 'Ws',
onClick: text => {
if( text.match(/^\[[\S]*\]$/g) ){
text = text.replace(/\[/g, '');
} else {
text = text.replace(/\[[\S]*[\s]/g, '');
}
text = text.replace(/\]/g, '').replace(/^\s+/, '');
const uri = encodeURI(text.replace(' ', '+'));
const regexp = /^[a-zA-Z0-9!-/:-@\[-`{-~\s]*$/gm
if (regexp.test(text)) {
window.open(`https://en.wikipedia.org/w/index.php?search=${uri}`);
} else {
window.open(`https://ja.wikipedia.org/w/index.php?search=${uri}`);
}
}
})
script.jsscrapbox.PopupMenu.addButton({
title: 'Wl',
onClick: text => {
const regexp = /^[a-zA-Z0-9!-/:-@\[-`{-~\s]*$/gm
if (regexp.test(text)) {
const regexp_en = /\[https\:\/\/en\.wikipedia\.org\/wiki\/(.+)\s(.+)\]/
if (regexp_en.test(text)){
// [https://en.wikipedia.org/wiki/${text} ${text}] → ${text} への変換
return text.replace(regexp_en, "$2")
} else {
return `[https://en.wikipedia.org/wiki/${encodeURIComponent(text)} ${text}]`
}
} else {
const regexp_ja = /\[https\:\/\/ja\.wikipedia\.org\/wiki\/(.+)\s(.+)\]/
if (regexp_ja.test(text)){
// [https://ja.wikipedia.org/wiki/${text} ${text}] → ${text} への変換
return text.replace(regexp_ja, "$2")
} else {
return `[https://ja.wikipedia.org/wiki/${encodeURIComponent(text)} ${text}]`
}
}
}
})