Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
70 lines (54 loc) · 2.27 KB
/
Copy pathcontent.js
File metadata and controls
70 lines (54 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* @Date: 2022-12-06 17:13:35
* @LastEditors: xzz
* @LastEditTime: 2023-04-15 16:48:49
*/
// 'use strict'默认启用
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './src/css/style' //引入自定义的所有css入口文件
// //---------------引入所有API挂载到全局----------
import{ contentApi as API} from './src/api/contentApi/index'
window.API = API
// ------批量-----引入----各个平台-----实例---------
import platformObj from './src/pages/importPages'
// 开发模式时 的 自动刷新
if(DEBUG){ // 开发模式时为真 // 生产模式为假
const { createWsConnect } = require('ws-reload-plugin')
createWsConnect({})
}
//------------vue实例-----挂载入口---------------------
import { copy } from './src/api/directive'
function createEntry(myapp,id){
const el = document.querySelector('body');
if (el) {
el.insertAdjacentHTML('afterbegin',`<div id="${id}"></div>`)
const xzzapp = createApp(myapp)
const pinia = createPinia()
xzzapp.directive('copy', copy)
xzzapp.use(pinia).mount(`#${id}`)
}
}
async function startGenerate() { // 决定是否生成页面进行挂载
// 检查当前网页 区分平台
let checkPlatform = location.host.match(/zhihu|csdn|juejin|jianshu|google|bilibili/)
checkPlatform = checkPlatform ? checkPlatform[0] : ''
// 检查当前平台开关是否开启
const openPlatformArr = await API.Storage.get('platformArr') || []
const checkSwitch = openPlatformArr.find(item => item.name == checkPlatform)?.status
checkSwitch ? createEntry(platformObj[checkPlatform], `platform${checkPlatform}`) : console.log(`${checkPlatform}平台未加载,请排查!`)
}
//-----------通过inject渠道------注入js到任意页面----且共享浏览器window--------------
API.injectFile()
// 上面注入需要先于vue实例生成, 这样注入就可以在mounted里执行
startGenerate()
//liaoxuefeng 临时添加 博客站 广告屏蔽
if(location.host.includes('liaoxuefeng')) {
// x-sidebar-left-bottom
const hideTag = ["#x-sidebar-left-bottom", ".adsbygoogle.adsbygoogle-noablate", "#x-content-bottom"]
let str = ``
hideTag.map(item => {
str += `${item}{ display: none !important;}`
})
API.appendStyle(str)
}