์ง์ document-start
์ ๋ํด @run-at
.
์์ธํ ๋ด์ฉ์ #2483์ ์ฐธ์กฐํ์ญ์์ค. ์ด๊ฒ์ "๋ถ๊ฐ๋ฅ"ํ ์ ์์ต๋๋ค.
content_scripts
๋งค๋ํ์คํธ ํค์ run_at
์์ฑ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
4๋ ์ ์ Chrome์ ๋ํ ์ํ๊น์์ ๊ณต์ ํ์ต๋๋ค. ์ด์ ๋ค์ Firefox๋ฅผ ์ํด. ๐ญ
๋ด ์ ์์ https://bugs.chromium.org/p/chromium/issues/detail?id=257956 ์์ ๋ฐ๊พธ๊ณ ์ถ์ต๋๋ค.
tabs.insertCSS/executeScript๋ ํญ์ URL์ด ๋น์ด ์์ง ์๊ฒ ์ค์ ๋ ๋๊น์ง CSS/JS๋ฅผ ์ฝ์ ํด์ผ ํ๋ฉฐ(not null, not undefined, not empty string ""), ํญ์ด ์ ๊ฑฐ/๋ณ๊ฒฝ๋๋ฉด ์ทจ์๋ฉ๋๋ค.
WebExtension API๋ ๊ฐ์ ๋์ด์ผ ํฉ๋๋ค.
@iology ์ ๋ด ์ ์์
๋ค์์ ๋ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ฌ ๊ทธ๋ ๊ฒ ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํด์ผ ํฉ๋๋ค. (์์ ์ ์ผ๋ก ์๋ํด์ผ ํจ)
/**
* <strong i="8">@typedef</strong> UserScript
* <strong i="9">@property</strong> {Object} header The parsed header of a script
* <strong i="10">@property</strong> {String} script The raw script data
* <strong i="11">@property</strong> {String} type The script media type (in case a script is WebAssembly
* or something other than JavaScript)
*/
/** The load state of this script. Used by the `matches()` function */
const READY_STATE = document.readyState;
(async () => {
(await (browser.storage.local.get({scripts: []}) // Excuse this horrible code style
.then(ret => ret.scripts))) // of combining `await` and `.then()`
.forEach(/* <strong i="12">@param</strong> {UserScript} script */ script => {
if (matches(script.header)) {
let scriptTag = document.createElement("script");
scriptTag.setAttribute("type", script.type)
scriptTag.textContent = script.script;
document.appendChild(scriptTag);
}
});
})();
/**
* Checks if this script matches this page and @run-at property.
*
* <strong i="13">@param</strong> {Object} scriptHeader The parsed header of a script
* <strong i="14">@return</strong> {boolean} `true` if this page matches, `false` otherwise
*/
function matches(scriptHeader) {
// Uses window.location and READY_STATE.
// TODO: Implement
}
@ExE-Boss ํ์ฅ ์ ์ฅ์์์ ์คํฌ๋ฆฝํธ๋ฅผ ๊ฒ์ํ ๋์ฏค์๋ ํ์ด์ง์ ์ผ๋ถ๊ฐ ์ด๋ฏธ ๋ก๋๋์ด ์์ ๊ฒ์ ๋๋ค.
๋๋ ๊ทธ๊ฒ์ ์๊ณ ์์ง๋ง WebExtensions๊ฐ ๋ณธ์ง์ ์ผ๋ก ๋น๋๊ธฐ์์ด๋ผ๋ ์ฌ์ค ๋๋ฌธ์ ๊ทธ๋ ๊ฒ ํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ค์ ๋ก ๋ณด์ง ๋ชปํฉ๋๋ค.
@ExE-Boss, ๋ฒ๊ทธ์ง๋ผ( https://bugzilla.mozilla.org/show_bug.cgi?id=1332273 )๊ฐ ์์ต๋๋ค. ์ ์งํ๋๊ณ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ฉฐ @document-start ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค. FF57์ ์ฐฉ๋ฅํ ์ง ์ฌ๋ถ๋ ํ์คํ์ง ์์ต๋๋ค.
๋๋ ๊ทธ๊ฒ์ ์๊ณ ์์ง๋ง WebExtensions๊ฐ ๋ณธ์ง์ ์ผ๋ก ๋น๋๊ธฐ์์ด๋ผ๋ ์ฌ์ค ๋๋ฌธ์ ๊ทธ๋ ๊ฒ ํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ค์ ๋ก ๋ณด์ง ๋ชปํฉ๋๋ค.
@ExE-Boss ๋ง ๊ทธ๋๋ก ์ฐ๋ฆฌ๊ฐ ํด๊ฒฐํ๋ ค๋ ๋ฌธ์ ์ ๋๋ค.
๋๋ ๊ทธ๊ฒ์ ํด๊ฒฐํ๋ ค๊ณ ๋ ธ๋ ฅํ๊ณ ์์ง๋ง ๋ด ์๋ฃจ์ ์ ์ค์ ๋ก #2525์ ๋ํด์๋ง ์ ์๋ํฉ๋๋ค. ๊ทธ ์์ ๊น์ง ์ ์ฒด ํ์ด์ง๊ฐ ์์ ํ ๋ก๋๋์๊ธฐ ๋๋ฌธ์ ๋๋ค.
Violentmonkey๋ ์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค. Tampermonkey๊ฐ ์ด๋ค ํ๋ง๋ฒ์ ์ฌ์ฉํ๋์ง ํ์คํ์ง ์์ง๋ง document-start
์ค์
Tampermonkey 2.9 ๋ฐ ์ด์ ๋ฒ์ ์ GPL-3.0์ด๋ฉฐ GitHub์ ๊ฒ์๋์์ต๋๋ค . ๋๋ ๊ทธ๊ฒ์ ์กฐ์ฌํด ๋ณด์๊ณ ์ฒ์์๋ sync XHR ์ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ์๊ฐํ์ง๋ง ์กฐ๊ธ ๋ฒ์ 2.6์ ์ง์์ด ๋ฉ๋๋ค. .2767 .
๋๋ ๋ฌผ๊ฑด์ ๋์ฉํ๋ ๋ฐ ๊ด์ฌ์ด ์์ต๋๋ค. Tampermonkey์ ๋ ผ๋ฆฌ๋ฅผ ๋ค์ง๋ ๊ฒ์ ์ด๋ ต์ง ์์ง๋ง ๊ทธ๋ ๊ฒ ํ๋ ๊ฒ์ ๋ถ๋ฒ์ ๋๋ค.
@Sxderp Firefox 57์๋ง ํด๋น๋๋ฉฐ ํด๋น ๋ฒ๊ทธ๋ 58+์์ ์ฌ์ ํ ํด๊ฒฐ๋ ์ ์์ต๋๋ค.
์ฐธ๊ณ ๋ก Tampermonkey๋ ๋ฌธ์ ์์ ์์๋ ์ ๋ขฐํ ์ ์์ต๋๋ค. ์๋๋ฅผ ๋์ด๋ "์ฆ๊ฐ์ ์ธ" ์ฃผ์ ์ต์ (๋งค์ฐ ํดํค๋จ)์ด ์์ง๋ง xkcd.com๊ณผ ๊ฐ์ ๊ฐ๋จํ ํ์ด์ง์์๋ CSS(๋ฌธ์ ์์ ์ ํญ์ ์ฃผ์ ๋จ)๊ฐ ๋ก๋๋๊ธฐ ์ ์ ์ฌ์ ํ ํ๋์๊ฐ ๋ฐ์ํฉ๋๋ค. ๋๋ ๋ํ ๋๋๋ก ๋ค๋ฅธ ์ฌ์ดํธ์์ ํ๋์๋ฅผ ์ป์ต๋๋ค.
Tampermonkey์ ์ฝ๋๋ฅผ ๋ค์ง๋ ๊ฒ์ ์ด๊ฒ์ ์์๋ด๋ ๋ฐฉ๋ฒ์ด ์๋๋๋ค. ๋ํ, ๊ทธ๋ค์ด ์ฌ์ฉํ๋ ์ค์ ๋ฐฉ๋ฒ์ ๋ค๋ฅธ ์ฌ์ฉ์๊ฐ ์ ์ํ ํฌ๋ผ์์ ์ฐพ์ ์ ์์ต๋๋ค. ๋ฉ์๋ ๋ณต์ฌ๋ copy-vio๊ฐ ์๋๋ผ ์ฝ๋ ์์ฒด๋ฅผ ๋ณต์ฌํ๋ ๊ฒ์ ๋๋ค.
๊ทธ๋ฌ๋ ์ฐ๋ฆฌ๋ ๊ทธ๊ฒ์ด ๋ถ์์ ํ ํด๊ฒฐ์ฑ ์ด๋ผ๋ ๊ฒ์ ์๊ณ ์์ผ๋ฉฐ ์๋ฒฝํ ํด๊ฒฐ์ฑ ์ ์ํฉ๋๋ค.
์ด ์์
์ ์ํํ๋ ๋ฐฉ๋ฒ์ด ๋ฐ๊ฒฌ๋๋ฉด ์คํฌ๋ฆฝํธ๊ฐ ์ ์ด๋ ๊ตฌ์ฑ ์ต์
์ ํ์ ์งํฉ์ ๋๊ธฐ์ ์ผ๋ก ์ฝ์ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ์ด๋ฅผ ํตํด ํด๊ฒฐํ ์ ์๋ ๋ฌธ์ ์ ์๋ https://github.com/ccd0/4chan-x/issues/1627์ ์ฐธ์กฐ localStorage
๋ฅผ ์ง์๋๋ค.
์ด ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ด ๋ฐ๊ฒฌ๋๋ฉด ์คํฌ๋ฆฝํธ๊ฐ ์ ์ด๋ ๊ตฌ์ฑ ์ต์ ์ ํ์ ์งํฉ์ ๋๊ธฐ์ ์ผ๋ก ์ฝ์ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋จ๊ธฐ๊ฐ์ ์๋๋๋ค. ๋๊ธฐ ๋ฐฉ์์ผ๋ก (get|set)Value ์ ์ฅ์์ ํต์ ํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ์๋ง๋ ๊ตฌ์ฑ ๊ฐ์ด ์๋ ๋ณ์๊ฐ ์คํฌ๋ฆฝํธ์ ์ ์ญ ๋ฒ์์ ์ฃผ์ ๋๋ GM ๋ถ๋ถ์ ๋ํ ์ผ์ข ์ ์ฃผ์ ์ผ ๊ฒ์ ๋๋ค. ๊ทธ๊ฒ์ด ๋ด๊ฐ ์๊ฐํ ์ ์๋ ์ต์ ์ด๊ณ , ๋ณ๋ก ์ข์ง ์์ต๋๋ค.
์๋ง๋ ๊ตฌ์ฑ ๊ฐ์ด ์๋ ๋ณ์๊ฐ ์คํฌ๋ฆฝํธ์ ์ ์ญ ๋ฒ์์ ์ฃผ์ ๋๋ GM ๋ถ๋ถ์ ๋ํ ์ผ์ข ์ ์ฃผ์ ์ผ ๊ฒ์ ๋๋ค. ๊ทธ๊ฒ์ด ๋ด๊ฐ ์๊ฐํ ์ ์๋ ์ต์ ์ด๊ณ , ๋ณ๋ก ์ข์ง ์์ต๋๋ค.
์๋ง๋ GM
๊ฐ์ฒด์ ์ผ๋ถ์ผ ๊ฒ์
๋๋ค. GM.initValues.yourVariable
์ ๊ฐ์ ๊ฒ์
๋๋ค.