segmentfault现在比较恶心, 必须登陆后才能复制文章的内容,索性自己分析了下前端代码逻辑,自己写了油猴子的脚本。
js前端的触发禁止右键的复制代码如下:
1 2 3 4 5 6 7 |
document.querySelectorAll("article.article").forEach(function (t) { t.addEventListener("copy", function (t) { if (!n("#SFUserId").length) return new s.g, t.preventDefault(), !1 }), |
解决办法:
1. 先给chrome或者firefox装 油猴子插件, 我用的插件是 Tampermonkey 。
2. 新建一个脚本,然后把下面的代码复制进去(github地址:https://gist.github.com/ksharpdabu/26f15063157cc8bd292bf245aa10640b):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// ==UserScript== // @name free-copy-on-segmentfault // @namespace http://tampermonkey.net/ // @version 0.1 // @description free copy on segmentfault.com // @author Alexy // @match https://segmentfault.com/* // @icon https://www.google.com/s2/favicons?domain=segmentfault.com // @grant none // ==/UserScript== (function () { 'use strict'; document.querySelectorAll("article.article").forEach(function (t) { t.addEventListener("copy", function (t) { event.stopPropagation(); }, true); }); })(); |
转载请注明:大步's Blog » segmentfault右键不能复制的破解方法