Greasemonkey脚本不适用于文本框的焦点

时间:2017-08-01 23:05:24

标签: javascript jquery event-handling handler greasemonkey

我正在开发一个Greasemonkey脚本,我希望在inputText文本框中填充文本时执行一个动作。 我正在粘贴我正在工作的Greasemonkey脚本。虽然我删除了链接,但出于安全目的使用谷歌。

// ==UserScript==
// @name            WCM
// @description     aaaaaa
// @author          abhi@
// @version         201708011431
// @include         http://*.google.com/*
// @include         https://*.google.com/*
// @require         http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v4.0.10.js
// @require         https://code.jquery.com/jquery-1.12.4.min.js
// @grant           GM_getResourceText
// @grant           GM_xmlhttpRequest
// @grant           GM_addStyle
// ==/UserScript==

(function($, Handlebars) {
 'use strict';
 console.log("[WCM] Starting...");

var fetchTeamData = function(host, pathname) {
    var result;
    var teamData;
    console.log("[WCM] Request HOST : " + host + " Request Pathname : " + pathname);
    try {
        // Insert job data after employee id
        var teamDataHtml = '<div> <table><tbody><tr><td><nobr>PRIMARY</nobr></td><td><input type="text" name="primary" id="primary"/></td></tr><tr><td><nobr>SECONDARY</nobr></td><td><input type="text" name="secondary" id="secondary"/></td></tr></tbody></table></div>';
        console.log("[WCM] HTML Rendering completed");
        $('body').append(teamDataHtml);
    } catch(e) {
        console.log("[WCM] ERROR : " + e);
    }
    console.log("[WCM] Stopping...");
    return result;
};

// Main function
var host = window.location.host;
var pathname = window.location.pathname;
var primary = $("#primary").val();
$.when(fetchTeamData(host, pathname));
$('#primary').focusout("enterKey",function(e){
                       GM_xmlhttpRequest({
                       method: "GET",
                       url: "http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=js&callback=" + primary,
                       headers: {
                       "Accept": "application/json"
                       },
                       onload: function(response) {
    responseString = response.responseText;
    secondaryGroups = JSON.parse(responseString);
    secondaryGroupsString = "";
    if (secondaryGroups.length === 0 ) {
        secondaryGroupsString = "None";
    }
    for (var secondaryGroup in secondaryGroups) {
        if (secondaryGroupsString !== "" )  {
            secondaryGroupsString += ", ";
        }
        secondaryGroupsString += secondaryGroups[secondaryGroup];
    }
    $('#secondary').html(secondaryGroupsString);
}
});
});
$('#primary').keyup(function(e){
                    alert("1a");
if(e.keyCode == 13)
{
    $(this).trigger("enterKey");
}
});
}(jQuery.noConflict(true), Handlebars));

但它不起作用。在文本框中输入文本时,页面加载不是动作

0 个答案:

没有答案