Skip to content

Instantly share code, notes, and snippets.

@mutoo
Last active December 12, 2019 04:10
Show Gist options
  • Save mutoo/e862d189dc3ca9a8c284adffd5b154a8 to your computer and use it in GitHub Desktop.
Save mutoo/e862d189dc3ca9a8c284adffd5b154a8 to your computer and use it in GitHub Desktop.
The wechat reading using canvas to render the text to prevent text copying, but there is a way to bypass it.
(()=>{
// hijack the fillText function to collect characters info
const c2d = CanvasRenderingContext2D.prototype;
const data = [];
const oldFillText = c2d.fillText;
c2d.fillText = function() {
const [char,x,y] = arguments;
data.push({
char,
x,
y
});
return oldFillText.apply(this, arguments);
}
$('.readerContent').__vue__.drawSomeTexts();
console.log(data.sort((a,b)=>{
if (a.y != b.y) {
return a.y - b.y
} else {
return a.x - b.x;
}
}
).map(d=>d.char).join(''));
}
)();
// Tested on this page:
// https://weread.qq.com/web/reader/42632ab05a9bc14cef1d78ak5cb31e021615ed74f14adf2
// Output:
// 第十六章 三体、哥白尼、宇宙橄榄球、三日凌空从叶文洁家里出来以后,汪淼心绪难平,这两天的遭遇和红岸的故事,这两件不相干的事纠结在一起,使世界在一夜之间变得异常陌生。回到家后,为了摆脱这种心绪,他打开电脑,穿上V装具,第三次进入《三体》。他的心态调整得很成功,当登录界面出现时,汪淼像换了一个人似的,心中立刻充满了莫名的兴奋。...
@mutoo
Copy link
Author

mutoo commented Dec 12, 2019

再花点时间看一下,发现文章内容直接存在 vue 组件里 chapterContentHtml

const div = document.createElement('div');
div.innerHTML = $('.readerContent').__vue__.chapterContentHtml;
console.log(div.innerText);

Output:

    刘慈欣给电子书读者的寄语

    读者朋友们大家好!

    物理学中的三体问题看似简单,实则极其复杂,且至今无解,正是对这样一个基础问题的想象,产生了《三体》系列这三部小说。《三体》表达了对广漠而寂静的宇宙的敬畏,和对宇宙中可能存在的智慧他者的想象。也许,对这两方面的想象和思考触及了我们精神世界中最深层和最本质的部分,因而这三部小说才能被这么多的人阅读,产生了这么多的共鸣和理解。正像看似简单的三体问题仍然无解,在万分复杂的大自然中我们也无法预测未来,但科幻小说至少能为我们描述出许多种未来可能的图景,让我们在走向未来的路程中拥有更广阔的视野和更丰富的思想。

    在《三体》电子书与读者见面之际,再次感谢广大读者的关注和支持,谢谢大家!

    刘慈欣

    2018.12.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment