Skip to content

Instantly share code, notes, and snippets.

@monsier-oui monsier-oui/Dreamlet.js
Last active Jan 23, 2018

Embed
What would you like to do?
pixivで夢小説(名前変換小説)を楽しめるブックマークレット
javascript:(
function(){
var f1 = "【苗字】";
var n1 = "【名前】";
var f2 = "";
var n2 = "";
var area = document.querySelectorAll('[id^="page-"]');
var len = area.length;
if(len > 0){
if(area[0].innerHTML.length > 0){
if(area[0].innerHTML.indexOf(f1) < 0) f1 = prompt("変換前の苗字を入力してください");
if(area[0].innerHTML.indexOf(n1) < 0) n1 = prompt("変換前の名前を入力してください");
}
if(f1 !== "") f2 = prompt("変換後の苗字を入力してください", f2);
if(n1 !== "") n2 = prompt("変換後の名前を入力してください", n2);
function dreamize(){
for(var i=0; i<len; i++){
if(f1 !== "" && f2 !== "") area[i].innerHTML = replaceName(area[i].innerHTML, f1, f2);
if(n1 !== "" && n2 !== "") area[i].innerHTML = replaceName(area[i].innerHTML, n1, n2);
}
}
dreamize();
var btn = document.querySelectorAll(".pager-prev, .pager-next, .prev-page, .next-page");
for(var i=0; i<btn.length; i++){
btn[i].addEventListener("click", 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
You can’t perform that action at this time.