Skip to content

Commit

Permalink
Fix ads
Browse files Browse the repository at this point in the history
  • Loading branch information
gavingaozhangmin committed Jul 28, 2023
1 parent d415874 commit a031f83
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 47 deletions.
8 changes: 2 additions & 6 deletions electron/main/core/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { getAsarPath, getResourcesPath, getStaticPath, getUserDataPath } from '.
import fs, { existsSync, readFileSync, writeFileSync } from 'fs'
import is from 'electron-is'
import { ShowErrorAndRelaunch } from './dialog'
import { ElectronBlocker } from '@cliqz/adblocker-electron';
import path from 'path'


export const ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33'
export const Referer = 'https://www.aliyundrive.com/'
Expand Down Expand Up @@ -243,10 +242,7 @@ export function createElectronWindow(width: number, height: number, center: bool
preload: getAsarPath('dist/electron/preload/index.js')
}
})
const adsRulePath: string = path.join(getStaticPath('engine'), 'ads_block.txt')
const blocker =
ElectronBlocker.parse(fs.readFileSync(adsRulePath, 'utf-8'));
blocker.enableBlockingInSession(session.defaultSession);


win.removeMenu()
if (is.dev()) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"node": ">=16.0.0"
},
"dependencies": {
"@cliqz/adblocker-electron": "^1.26.6",
"@cliqz/adblocker-electron-preload": "^1.26.6"

},
"devDependencies": {
"@arco-design/web-vue": "^2.45.3",
Expand Down
76 changes: 37 additions & 39 deletions src/resource/searchIndex.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<iframe class="custom-webview" src="https://www.pansearch.me" ref="iframeRef"></iframe>
<iframe class="custom-webview" src="https://www.upyunso.com/" ref="iframeRef"></iframe>
</div>
</template>

Expand All @@ -20,41 +20,41 @@ export default {
iframe.addEventListener('load', () => {
// @ts-ignore
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
const intervalId = setInterval(() => {
const element2 = iframeDocument.querySelector('div._4zmcr4t')
if (element2) {
element2.click()
}
// 查找所有的 tab 元素
const tabs = iframeDocument.querySelectorAll('.tab')
// 自动点击元素
const targetTab = document.querySelector('.tab:nth-child(2)')
if (targetTab) {
// @ts-ignore
targetTab.click()
}
// 删除其他 tab 元素
// @ts-ignore
tabs.forEach(tab => {
if (tab !== targetTab) {
tab.remove()
}
})
const footElement = iframeDocument.querySelector('.flex.flex-wrap.gap-2')
if (footElement) {
footElement.remove()
}
const header = iframeDocument.querySelector('.navbar.bg-neutral.text-neutral-content')
if (header) {
header.remove()
}
const divider = iframeDocument.querySelector('.divider')
if (divider) divider.remove()
const warn = iframeDocument.querySelector('.alert.alert-warning.shadow-lg')
if (warn) warn.remove()
}, 100)
// const intervalId = setInterval(() => {
// const element2 = iframeDocument.querySelector('div._4zmcr4t')
// if (element2) {
// element2.click()
// }
// // 查找所有的 tab 元素
// const tabs = iframeDocument.querySelectorAll('.tab')
//
// // 自动点击元素
// const targetTab = document.querySelector('.tab:nth-child(2)')
// if (targetTab) {
// // @ts-ignore
// targetTab.click()
// }
//
// // 删除其他 tab 元素
// // @ts-ignore
// tabs.forEach(tab => {
// if (tab !== targetTab) {
// tab.remove()
// }
// })
// const footElement = iframeDocument.querySelector('.flex.flex-wrap.gap-2')
// if (footElement) {
// footElement.remove()
// }
// const header = iframeDocument.querySelector('.navbar.bg-neutral.text-neutral-content')
// if (header) {
// header.remove()
// }
// const divider = iframeDocument.querySelector('.divider')
// if (divider) divider.remove()
// const warn = iframeDocument.querySelector('.alert.alert-warning.shadow-lg')
// if (warn) warn.remove()
// }, 100)
iframeDocument.addEventListener('click', (event: any) => {
const target = event.target;
Expand All @@ -64,9 +64,7 @@ export default {
event.preventDefault();
modalDaoRuShareLink(url);
} else {
if (!url.includes('pansearch.me')) {
event.preventDefault();
}
event.preventDefault();
}
})
})
Expand Down

0 comments on commit a031f83

Please sign in to comment.