-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const thisGlobal = window | ||
|
||
if (typeof thisGlobal.GM === 'undefined') { | ||
thisGlobal.GM = {} as any | ||
} | ||
|
||
export function getGMWindow () { return thisGlobal } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
if (typeof (window as any).GM_addStyle == 'undefined') { | ||
(window as any).GM_addStyle = (cssContent: string) => { | ||
let head = document.getElementsByTagName('head')[0] | ||
import { getGMWindow } from "./GM" | ||
|
||
const w = getGMWindow() | ||
|
||
if (typeof w.GM_addStyle === 'undefined') { | ||
w.GM_addStyle = function GM_addStyle(cssContent: string) { | ||
const head = document.getElementsByTagName('head')[0] | ||
if (head) { | ||
let style = document.createElement('style') | ||
style.setAttribute('type', 'text/css') | ||
style.textContent = cssContent | ||
head.appendChild(style) | ||
return style | ||
const styleElement = document.createElement('style') | ||
styleElement.setAttribute('type', 'text/css') | ||
styleElement.textContent = cssContent | ||
head.appendChild(styleElement) | ||
return styleElement | ||
} | ||
return null | ||
} | ||
} | ||
|
||
if (typeof w.GM.addStyle === 'undefined') { | ||
w.GM.addStyle = GM_addStyle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
declare function GM_addStyle(content: string): undefined; | ||
declare function GM_addStyle(content: string): any; | ||
declare function GM_setValue(key: string, value: T): undefined; | ||
declare function GM_getValue<T>(key: string, defaultValue: T): T | ||
|
||
declare interface Window { | ||
GM: { | ||
addStyle: GM_addStyle, | ||
}, | ||
GM_addStyle: GM_addStyle, | ||
GM_setValue: GM_setValue, | ||
GM_getValue: GM_getValue, | ||
} |