将蛋糕英语中的字幕提取出来,打印后便于复习背诵。
需要使用油猴之类的扩展调用
// ==UserScript==
// @name 蛋糕英语自动提取对话
// @namespace cake
// @match http://pap.baicizhan.com/*
//@require http://code.jquery.com/jquery-latest.js
// @grant none
// ==/UserScript==
//
//
$(document).ready(function(){
$("body").css('height','90%');
});
var btn05=$("<input type='button' id='wzmBtn' value='提取文本' style='height:50px;font-size: 0.4rem'>");
$("body").append(btn05);
$("div.page-sentence-words-341gD").after(btn05);
document.getElementById("wzmBtn").addEventListener("click", function(){
showtext();
});
var area01=$("<input id='area01' >");
$("body").append(area01);
var area02=$("<textarea id='area02' style='height:400px;width:100%;font-size: 0.4rem'></textarea>");
$("body").append(area02);
function showtext(){
text = '';
$t = $("span").each(function() {
//text += $(this).children("span")html();
//div.group-2PoM9 contents()
text += $(this).html();
});
var shorttext = (delsub(text, "<i>"));
shorttext = delsub(shorttext, "</i>");
shorttext = delsub(shorttext, " ")
console.log(shorttext);
document.getElementById("area01").value+='\n'+shorttext;
$("#area02").html(document.getElementById("area01").value);
$("div.page-sentence-words-341gD").after(area02);
$("i.mod-next-1LINN").parent().after(btn05);
}
function delsub(father, sub) {
var newfather = father;
for (var i in father) {
//console.log(i, father[i]);
}
var n = newfather.length;
var delflag = true;
var t = 0;
do {
var f = newfather.replace(sub, ' ');
if (f.length < newfather.length) {
newfather = f;
delflag = true;
t++;
} else {
delflag = false;
}
}
while (delflag);
return newfather;
}