需要使用火狐并安装油猴之类的扩展。
蛋糕英语网页中,使用了一些方法,使得用户无法复制英语视频中的字幕,用以下代码可以复制出对话文本。
// ==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;
}