Skip to content

Commit

Permalink
feat: remove github attach copy
Browse files Browse the repository at this point in the history
  • Loading branch information
neo committed Mar 5, 2023
1 parent 5801da4 commit bcef0d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
48 changes: 1 addition & 47 deletions src/ContentScript/feature/attachCopy/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function appendAttachCopy(target: string) {

button
.click(function() {
// eslint-disable-next-line @typescript-eslint/no-invalid-this
const ele = $(this).find('.masterfont');

if (copyElementContent(pre)) {
Expand Down Expand Up @@ -47,53 +48,6 @@ export function appendAttachCopy(target: string) {
}
}

export function initGitHub() {
appendAttachCopy('.repository-content div#readme article');

// code in issue
appendAttachCopy('#discussion_bucket .js-discussion');
}

function observeReadme(cb: () => void) {
// 选择需要观察变动的节点
const targetNode = document.getElementById('tree-holder');

// 观察器的配置(需要观察什么变动)
const config = {
childList: true,
subtree: true,
};

// 当观察到变动时执行的回调函数
const callback = function(mutationsList: any, _observer: any) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
if (mutation.target.classList.value.indexOf('blob-viewer') >= 0) {
cb && cb();
}
}
}
};

const observer = new MutationObserver(callback);

targetNode && observer.observe(targetNode, config);
}

export function initGitLab() {
let flag = false;

observeReadme(function() {
// will trigger many times
if (!flag) {
appendAttachCopy('#tree-holder .file-holder .file-content');
flag = true;
}
});

appendAttachCopy('#content-body .issue-details');
}

export function initGitee() {
appendAttachCopy('#tree-holder #git-readme .file_content');
appendAttachCopy('#git-issue .git-issue-body');
Expand Down
11 changes: 1 addition & 10 deletions src/ContentScript/feature/attachCopy/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import GitMaster from '../../PageLife/core/GitMaster';
import { initGitee, initGitLab, initGitea } from './copy';
import { initGitee, initGitea } from './copy';

export default (ctx: GitMaster) => {
const register = () => {
ctx.helper.documentLoadedPlugins.register('gitlab-attach-copy', {
async handle() {
initGitLab();
},
config: [],
scope: ['gitlab'],
repeatOnAjax: true,
});

ctx.helper.documentLoadedPlugins.register('gitee-attach-copy', {
async handle() {
initGitee();
Expand Down

0 comments on commit bcef0d9

Please sign in to comment.