Greasemonkey: ๋‹ค๋ฅธ Greasemonkey ์‚ฌ์šฉ์ž ์Šคํฌ๋ฆฝํŠธ์—์„œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2016๋…„ 10์›” 28์ผ  ยท  8์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: greasemonkey/greasemonkey

์•ˆ๋…•ํ•˜์„ธ์š”,

์ €๋Š” Greasemonkey๋ฅผ ์ฒ˜์Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
๋‹ค๋ฅธ Greasemonkey ์‚ฌ์šฉ์ž ์Šคํฌ๋ฆฝํŠธ์—์„œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๊นŒ?

๊ฐ์‚ฌ ํ•ด์š”.

๋ชจ๋“  8 ๋Œ“๊ธ€

์•„๋‹ˆ์š”, ๋‹ค๋ฅธ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์–ด๋–ค ์ˆ˜๋‹จ์„ ํ†ตํ•ด API๋ฅผ ๋…ธ์ถœํ•˜๋ ค๋Š” ๋…ธ๋ ฅ์„ ๊ธฐ์šธ์ด์ง€ ์•Š๋Š” ํ•œ ์•„๋‹™๋‹ˆ๋‹ค.

๋‚ด๋ถ€์ ์œผ๋กœ๋Š” ๋ฐฉ๋ฒ•์ด ์—†์ง€๋งŒ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋…ธ์ถœ๋œ ๊ธฐ๋Šฅ์ด ์žˆ๋Š” ์Šคํฌ๋ฆฝํŠธ:

unsafeWindow.hello = hello;
function hello() {alert("hello world");}

ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ

hello();

๊ทธ๊ฒŒ ์š”์ง€์ž…๋‹ˆ๋‹ค.

๋ฌผ๋ก  ๊ทธ๊ฒƒ์€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ์Šคํฌ๋ฆฝํŠธ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์›น ์‚ฌ์ดํŠธ์—์„œ ํ˜ธ์ถœ ํ•  ์ˆ˜ ์žˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

์ง„์‹ค. ์•”ํ˜ธ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•˜์‹ญ์‹œ์˜ค.

๊ฐ™์€ ํƒญ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

// ==UserScript==
// <strong i="5">@name</strong>        Test call 1
// <strong i="6">@namespace</strong>   https://github.com/tiansh/
// <strong i="7">@include</strong>     http://example.com/
// <strong i="8">@version</strong>     1
// <strong i="9">@grant</strong>       unsafeWindow
// ==/UserScript==

unsafeWindow.x = function (str, callback) {
  console.log('%o.x: %o', this, arguments);
  alert('x says: ' + str);
  callback(str + 'from x');
};
// ==UserScript==
// <strong i="12">@name</strong>        Test call 2
// <strong i="13">@namespace</strong>   https://github.com/tiansh/
// <strong i="14">@include</strong>     http://example.com/
// <strong i="15">@version</strong>     1
// <strong i="16">@grant</strong>       unsafeWindow
// ==/UserScript==

setTimeout(function () {

unsafeWindow.x('hello', function (nstr) {
  console.log('%o.y: %o', this, arguments);
  alert('y says: ' + nstr);
});

}, 0);

์›น ์‚ฌ์ดํŠธ์˜ ํŽ˜์ด์ง€์— ์žˆ๋Š” @the8472 ์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒŒ๋“œ๋ฐ•์Šค ๋ณดํ˜ธ๋กœ ์ธํ•ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

@tiansh , ์ด ์˜ˆ์ œ์—์„œ ์ƒŒ๋“œ๋ฐ•์Šค ๋ณดํ˜ธ๋Š” <strong i="6">@grant</strong> unsafeWindow ์˜ํ•ด ๋น„ํ™œ์„ฑํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

@pyhedgehog ์‹œ๋„ํ•ด

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰