Skip to content

Commit

Permalink
feat: auto selection
Browse files Browse the repository at this point in the history
  • Loading branch information
WindRunnerMax committed Dec 8, 2024
1 parent 427f6ae commit ee3c1f1
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 57 deletions.
4 changes: 2 additions & 2 deletions packages/force-copy/src/inject/modules/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { CONTEXT_MENU_TYPE, COPY_TYPE, KEYBOARD_TYPE } from "@/utils/constant";
import type { WebSite } from "../types/website";
import { EVENTS_ENUM, EventBus } from "../utils/bus";
import { onCopyKeyboardHandler, stopNativePropagation } from "../utils/events";
import { STYLE_ID, AUTO_USER_SELECT } from "../utils/styles";
import { STYLE_ID, AUTO_USER_SELECT, AUTO_SELECTION } from "../utils/styles";

export const Basic: WebSite = {
regexp: /.*/,
start(type) {
if (type === COPY_TYPE) {
styles.insertCSS(STYLE_ID, AUTO_USER_SELECT);
styles.insertCSS(STYLE_ID, AUTO_USER_SELECT + AUTO_SELECTION);
EventBus.on(EVENTS_ENUM.COPY_CAPTURE, stopNativePropagation);
EventBus.on(EVENTS_ENUM.KEY_BOARD_CAPTURE, onCopyKeyboardHandler);
EventBus.on(EVENTS_ENUM.SELECT_START_CAPTURE, stopNativePropagation);
Expand Down
34 changes: 0 additions & 34 deletions packages/force-copy/src/inject/modules/boke.ts

This file was deleted.

12 changes: 4 additions & 8 deletions packages/force-copy/src/inject/modules/doc88.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ const onMouseUpCapture = () => {
};
const init = () => {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error global
window.Config && (window.Config.vip = 1) && (window.Config.logined = 1);
const hook = () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error global
const api = window.Core.Annotation.api;
const keys = Object.keys(api).filter(key => isString(api[key]));
const duplication: Record<string, unknown> = {};
Expand All @@ -47,12 +45,10 @@ const init = () => {
});
});
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error global
if (window.Core) {
hook();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error global
} else if (window.Core === null) {
delayExecute(PAGE_LOADED).then(hook);
} else {
Expand Down
3 changes: 1 addition & 2 deletions packages/force-copy/src/inject/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { WebSite } from "../types/website";
import { Basic } from "./basic";
import { Boke } from "./boke";
import { Doc88 } from "./doc88";
import { DocIn } from "./docin";
import { QQDoc } from "./qq-doc";
import { QQPpt } from "./qq-ppt";
import { Wenku } from "./wenku";
import { Zhihu } from "./zhihu";

export const websites: WebSite[] = [Wenku, Doc88, QQDoc, DocIn, Boke, Zhihu, QQPpt, Basic];
export const websites: WebSite[] = [Wenku, Doc88, QQDoc, DocIn, Zhihu, QQPpt, Basic];
3 changes: 1 addition & 2 deletions packages/force-copy/src/inject/modules/wenku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const onMouseUp = (event: MouseEvent) => {
try {
const elements = document.querySelectorAll("#app > div");
for (const item of elements) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error __vue__
const vue = item.__vue__;
if (vue) {
const text = vue.$store.getters["readerPlugin/selectedTextTrim"];
Expand Down
13 changes: 7 additions & 6 deletions packages/force-copy/src/inject/utils/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export const ALLOW_PAINT = "@media print{body{display:block !important;}} ";
export const COPY_BUTTON_STYLE =
".__copy-button {width: 60px; height: 30px; background: #4C98F7;color: #fff;position: absolute;" +
"z-index: -1000;opacity: 0;display: flex;justify-content: center;align-items: center;border-radius: 3px;" +
"font-size: 13px;cursor: pointer;transition: opacity 0.3s;}";
"font-size: 13px;cursor: pointer;transition: opacity 0.3s;} ";

export const AUTO_SELECTION =
":not(input):not(textarea)::selection {" +
" background-color: #BEDAFF !important;" +
" }" +
" " +
" background-color: #BEDAFF !important;" +
" background-color: highlight !important;" +
"} " +
":not(input):not(textarea)::-moz-selection {" +
" background-color: #BEDAFF !important;" +
"}";
" background-color: #BEDAFF !important;" +
" background-color: highlight !important;" +
"} ";
4 changes: 2 additions & 2 deletions packages/water-mark/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { common } from "./modules/common";
import { basic } from "./modules/basic";
import type { Website } from "./types/website";

const websites: Website[] = [common];
const websites: Website[] = [basic];
const web = websites.find(item => item.regexp.test(location.href));
web && web.init();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FALLBACK_CLASS, OPACITY_BACKGROUND_PROPERTY, OPACITY_PROPERTY } from ".
import { inspectWaterMarkDOM } from "../utils/dom";
import { injectCSSEarly } from "../utils/styles";

export const common: Website = {
export const basic: Website = {
regexp: /.*/,
init: () => {
const observer = MutationObserver.prototype.observe;
Expand Down

0 comments on commit ee3c1f1

Please sign in to comment.