Clippyjs не очень хорошо спроектирован для сценариев Tampermonkey, он ajaxes в других JS-файлах, таких как agent.js
, которые ожидают, что clippy
будет определено в области действия window
.
Это означает, что вы должны вставьте все в область страницы, например:
// ==UserScript==
// @name Clippy script demo injection
// @include https://stackoverflow.com/questions/*
// @grant none
// ==/UserScript==
/* global $, clippy */
/* eslint-disable no-multi-spaces */
//-- These particular target page(s) already have jQuery, otherwise addJS_Node() it too.
$("head").append ( `
<link href="//gitcdn.xyz/repo/pi0/clippyjs/master/assets/clippy.css"
rel="stylesheet" type="text/css">
` );
addJS_Node (null, "https://unpkg.com/clippyjs@latest", null, startClippy);
//-- addJS_Node waits for clippyjs to load before running this...
function startClippy () {
clippy.load ('Merlin', function (agent) {
agent.show ();
} );
}
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}