Last active
February 17, 2023 15:19
-
-
Save monsier-oui/9188018 to your computer and use it in GitHub Desktop.
pixivで夢小説(名前変換小説)を楽しめるブックマークレット
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:( | |
function(){ | |
var f1 = "【苗字】"; | |
var n1 = "【名前】"; | |
var f2 = "☆"; | |
var n2 = "★"; | |
var area = document.querySelectorAll('[id]'); | |
var len = area.length; | |
if(len > 0){ | |
var content = area[0].innerHTML; | |
if(content.length > 0){ | |
if(content.indexOf(f1) < 0) f1 = prompt("変換前の苗字を入力してください"); | |
if(content.indexOf(n1) < 0) n1 = prompt("変換前の名前を入力してください"); | |
} | |
if(f1 !== "") f2 = prompt("変換後の苗字を入力してください", f2); | |
if(n1 !== "") n2 = prompt("変換後の名前を入力してください", n2); | |
function dreamize(){ | |
var node = null; | |
for(var i=0; i<len; i++){ | |
if(area[i].getAttribute('id').match(/^\d+$/g)){ | |
node = area[i].nextSibling; | |
break; | |
}else if(area[i].getAttribute('id') === 'novel-text-container'){ | |
node = area[i]; | |
break; | |
} | |
} | |
console.log('node:', node); | |
if(node){ | |
if(f1 !== "" && f2 !== "") node.innerHTML = replaceName(node.innerHTML, f1, f2); | |
if(n1 !== "" && n2 !== "") node.innerHTML = replaceName(node.innerHTML, n1, n2); | |
} | |
} | |
dreamize(); | |
}else{ | |
alert("エラーが発生しました。"); | |
} | |
// 置換 | |
function replaceName(str, before, after){ | |
if(before !== "" && after !== ""){ | |
var reg = new RegExp(before, "g"); | |
return str.replace(reg, after); | |
} | |
return str; | |
} | |
} | |
)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment