Greasemonkey: كيفية استدعاء وظيفة في نص مستخدم Greasemonkey آخر؟

تم إنشاؤها على ٢٨ أكتوبر ٢٠١٦  ·  8تعليقات  ·  مصدر: greasemonkey/greasemonkey

أهلا،

أنا جديد في Greasemonkey.
هل هناك أي طريقة لاستدعاء وظيفة في نص مستخدم Greasemonkey آخر؟

شكرا.

ال 8 كومينتر

لا ، إلا إذا بذل النص الآخر بعض الجهد لكشف واجهات برمجة التطبيقات من خلال بعض الوسائل.

لا توجد طريقة داخلية للقيام بذلك ، ولكن هناك حل.

البرنامج النصي مع وظيفة مكشوفة:

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 هل حاولت؟ مع GM 2/3؟

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات