Skip to content

Commit

Permalink
feat: qq slider #134
Browse files Browse the repository at this point in the history
  • Loading branch information
WindRunnerMax committed Jul 21, 2024
1 parent 07f6fe4 commit eb0ad20
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/copy/meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "🔥🔥🔥文本选中复制🔥🔥🔥",
"namespace": "https://github.com/WindrunnerMax/TKScript",
"version": "6.2.3",
"version": "6.2.4",
"description": "解除网站不允许复制的限制,文本选中后点击复制按钮即可复制,主要用于 百度文库 道客巴巴 腾讯文档 豆丁网 无忧考网 学习啦 蓬勃范文 思否社区 力扣 知乎 语雀 等",
"author": "Czy",
"match": [
Expand All @@ -22,6 +22,7 @@
"*://z.30edu.com.cn/*",
"*://docs.qq.com/doc/*",
"*://docs.qq.com/sheet/*",
"*://docs.qq.com/slide/*",
"*://boke112.com/post/*",
"*://*.yuque.com/*",
"*://www.commandlinux.com/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/copy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MOUSE_UP } from "./constant/event";
const content = getSelectedText();
if (isEmptyContent(content)) {
instance.hide();
return "";
return void 0;
}
instance.onCopy(content, e);
};
Expand Down
10 changes: 5 additions & 5 deletions packages/copy/src/modules/docqq.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { TEXT_HTML, TEXT_PLAIN } from "../utils/copy";
import utils from "../utils/event";
import { instance } from "../utils/instance";
import type { Website } from "../websites";

const website: Website = {
regexp: /.*docs\.qq\.com\/.+/,
regexp: /.*docs\.qq\.com\/(doc)|(sheet)\/.+/,
config: {
initCopyEvent: false,
captureInstance: true,
delay: 100,
},
init: function () {
window.onload = () => {
utils.hideButton();
instance.disable();
};
},
getSelectedText: function () {
// QQ Doc
if (unsafeWindow.pad && unsafeWindow.pad.editor && !unsafeWindow.pad.editor.isCopyable()) {
utils.showButton();
instance.enable();
const editor = unsafeWindow.pad.editor;
if (editor.getCopyContent) {
const content = editor.getCopyContent() || {};
Expand Down Expand Up @@ -48,7 +48,7 @@ const website: Website = {
unsafeWindow.SpreadsheetApp.permissions.sheetStatus.canEdit &&
unsafeWindow.SpreadsheetApp.permissions.sheetStatus.canEdit() === false
) {
utils.showButton();
instance.enable();
const SpreadsheetApp = unsafeWindow.SpreadsheetApp;
const [selection] = SpreadsheetApp.view.getSelectionRanges();
if (selection) {
Expand Down
52 changes: 52 additions & 0 deletions packages/copy/src/modules/qq-slider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { instance } from "../utils/instance";
import type { Website } from "../websites";

const website: Website = {
regexp: /.*docs\.qq\.com\/slide\/.+/,
config: {
initCopyEvent: false,
captureInstance: true,
runAt: "document-end",
},
init: function () {
if (
unsafeWindow.__ARK_EXTENSION_SERVICE__ &&
!unsafeWindow.clientVars.privilegeAttribute.can_copy
) {
let webpackJsonp = unsafeWindow.webpackJsonp;
Object.defineProperty(unsafeWindow, "webpackJsonp", {
get() {
return webpackJsonp;
},
set(newValue) {
if (newValue.push.__HOOKED__) {
return;
}
webpackJsonp = newValue;
const originPush = webpackJsonp.push;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function push(...args: any[]) {
const [, mods] = args[0];
for (const [key, fn] of Object.entries(mods)) {
const stringifyFn = String(fn);
if (/this\.shouldResponseCopy/.test(stringifyFn)) {
const next = stringifyFn.replace(/this\.shouldResponseCopy\(/g, "(() => true)(");
// .replace(/this.storeManager=/g, "window.storeManager=this.storeManager=")
mods[key] = new Function(`return (${next})`)();
}
}
// @ts-expect-error this
return originPush.call(this, ...args);
}
push.__HOOKED__ = 1;
webpackJsonp.push = push;
},
});
}
window.onload = () => {
instance.disable();
};
},
};

export default website;
2 changes: 1 addition & 1 deletion packages/copy/src/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isString } from "./is";

const dom = {
export const dom = {
query: function (selector: string): null | HTMLElement {
return document.querySelector(selector);
},
Expand Down
4 changes: 3 additions & 1 deletion packages/copy/src/utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const stopNativePropagation = (event: Event): void => {
event.stopPropagation(); // 阻止该元素继续冒泡后的`on`同类事件触发
};

export default {
export const event = {
hideButton: (): void => {
instance.disable();
},
Expand Down Expand Up @@ -70,3 +70,5 @@ export default {
);
},
};

export default event;
34 changes: 22 additions & 12 deletions packages/copy/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,30 @@ for (const element of elements) {
/**
* Hook Function Call
*/
let index = 0;
const log = window.console.log;
(function reset() {
index = 0;
setTimeout(reset, 3000);
})();
const native = [Array.prototype.slice, Object.prototype.toString, Object.prototype.hasOwnProperty];
Function.prototype.call = function (dynamic, ...args) {
const context = Object(dynamic) || window;
const symbol = Symbol();
context[symbol] = this;
args.length === 2 && console.log(args);
try {
const result = context[symbol](...args);
delete context[symbol];
return result;
} catch (error) {
console.log("Hook Call Error", error);
console.log(context, context[symbol], this, dynamic, args);
return null;
if (
!dynamic ||
typeof dynamic !== "object" ||
native.includes(this) ||
!args.length ||
dynamic.nodeType
) {
return this.bind(dynamic)(...args);
}
index++;
if (index < 30) {
log("__dynamic", dynamic);
log("__args", args);
log("__this", this);
}
return this.bind(dynamic)(...args);
};

// =========================================================================== //
Expand Down
1 change: 1 addition & 0 deletions packages/copy/src/utils/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ class Instance {
}

export const instance = new Instance();

export default instance;
2 changes: 2 additions & 0 deletions packages/copy/src/websites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import wk from "./modules/wk";
import zhihu from "./modules/zhihu";
import edu30 from "./modules/edu30";
import docqq from "./modules/docqq";
import qqSlider from "./modules/qq-slider";
import boke112 from "./modules/boke112";
import diyifanwen from "./modules/diyifanwen";
import mbalib from "./modules/mbalib";
Expand Down Expand Up @@ -49,6 +50,7 @@ const websites: Website[] = [
wk,
zhihu,
edu30,
qqSlider,
docqq,
boke112,
diyifanwen,
Expand Down

0 comments on commit eb0ad20

Please sign in to comment.