Skip to content

Commit

Permalink
fix: 🐛 修复与 ios 油猴扩展的兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hymbz committed Jan 13, 2024
1 parent 7397e06 commit 1f76f64
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
last 5 Chrome versions
last 5 Firefox versions
last 5 Safari versions
last 5 iOS versions
14 changes: 8 additions & 6 deletions metaHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ const resourceList: Record<string, [string, string] | [string]> = {
'https://greasyfork.org/scripts/467177-dmzjdecrypt/code/dmzjDecrypt.js?version=1207199',
],
};

const resource = {
prod: Object.fromEntries(
Object.entries(resourceList).map(([k, v]) => [k, v.at(0)]),
),
dev: Object.fromEntries(
Object.entries(resourceList).map(([k, v]) => [k, v.at(-1)]),
),
dev: {} as Record<string, string | undefined>,
prod: {} as Record<string, string | undefined>,
};
Object.entries(resourceList).forEach(([k, v]) => {
const name = k.replaceAll('/', '|');
resource.prod[name] = v.at(0);
resource.dev[name] = v.at(-1);
});

/** 根据 index.ts 的注释获取支持站点列表 */
const getSupportSiteList = () => {
Expand Down
1 change: 1 addition & 0 deletions src/components/Manga/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const Manga: Component<MangaProps> = (props) => {
oncapture:keydown={handleKeyDown}
oncapture:keypress={stopPropagation}
oncapture:keyup={stopPropagation}
on:click={stopPropagation}
data-mobile={boolDataVal(store.isMobile)}
data-scroll-mode={boolDataVal(store.option.scrollMode)}
>
Expand Down
47 changes: 25 additions & 22 deletions src/helper/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,37 @@ const evalCode = (code: string) => {
* @param name \@resource 引用的资源名
*/
const selfImportSync = (name: string) => {
const code = name !== 'main' ? GM_getResourceText(name) : inject('main');
const code =
name !== 'main'
? GM_getResourceText(name.replaceAll('/', '|'))
: inject('main');
if (!code) throw new Error(`外部模块 ${name} 未在 @Resource 中声明`);

// 通过提供 cjs 环境的变量来兼容 umd 模块加载器
// 将模块导出变量放到 crsLib 对象里,防止污染全局作用域和网站自身的模块产生冲突
const runCode = `
window['${tempName}']['${name}'] = {};
${isDevMode ? `console.time('导入 ${name}');` : ''}
(function (process, require, exports, module, ${gmApiList.join(', ')}) {
${code}
})(
window['${tempName}'].process,
window['${tempName}'].require,
window['${tempName}']['${name}'],
{
set exports(value) {
window['${tempName}']['${name}'] = value;
},
get exports() {
return window['${tempName}']['${name}'];
},
window['${tempName}']['${name}'] = {};
${isDevMode ? `console.time('导入 ${name}');` : ''}
(function (process, require, exports, module, ${gmApiList.join(', ')}) {
${code}
})(
window['${tempName}'].process,
window['${tempName}'].require,
window['${tempName}']['${name}'],
{
set exports(value) {
window['${tempName}']['${name}'] = value;
},
${gmApiList
.map((apiName) => `window['${tempName}'].${apiName}`)
.join(', ')}
);
${isDevMode ? `console.timeEnd('导入 ${name}');` : ''}
`;
get exports() {
return window['${tempName}']['${name}'];
},
},
${gmApiList
.map((apiName) => `window['${tempName}'].${apiName}`)
.join(', ')}
);
${isDevMode ? `console.timeEnd('导入 ${name}');` : ''}
`;

Reflect.deleteProperty(unsafeWindow, tempName);
unsafeWindow[tempName] = crsLib;
Expand Down

0 comments on commit 1f76f64

Please sign in to comment.