我正在尝试为在线游戏开发脚本。他们在网页上使用angularJS。
是否可以附加以用户脚本编写的,以tampermonkey运行的角度控制器?这是我的代码的一部分:
// ==UserScript==
// @name Inventory extras
// @version 0.1
// @include gameurl.com/*/economy/inventory
// @description Table with licenses and taxes in the inventory. Scan for prices in sortable table. Also checks for the old license bug, when aliens are on top of the list of sellers. Now with job offers.
// @namespace myNamespace
// ==/UserScript==
var $ = jQuery;
function AddStyle(t) {
$("head").append("<style>" + t + "</style>");
}
(function() {
'use strict';
$("#sell_offers").after('<div class="taxTable" style="display: block;" ng-app="mainApp" ng-controller="licensesController">' + '<table id="licenses" width="100%">' + "<thead>" + "<tr>" + '<th style="height: 40px; text-align: center; padding-left: 0px;"> </th>" + "</tr>" + "</thead>" + "<tbody></tbody>" + "</table>" + "</div>");
$("#inventory_overview .taxTable table tbody").append("<tr ng-repeat='country in countries'><td style='padding-left: 5px;' colspan='9'>{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}</td></tr>");
var mainApp = angular.module("mainApp", []);
mainApp.controller('licensesController', function($scope) {
$scope.countries = [{locale:'en-US',name:'United States'}, {locale:'en-GB',name:'United Kingdom'}, {locale:'en-FR',name:'France'}]
});
})();
该示例的代码被剪切,并且可能包含一些错误。在主机页面执行功能时应该调用什么?
是的,我开始阅读教程,但是找不到关于tampermonkey和angularJS的任何东西。
编辑1:
$("#sell_offers").after('<div ng-controller="MyController"> Hello {{greetMe}}! </div>');
angular.module('myApp', [])
.controller('MyController', [
'$scope', function ($scope) {
$scope.greetMe = 'World';
}
]);
angular.element(function() {
angular.bootstrap(document, ['myApp']);
});
})();
仍然无法正常工作。 angular.min.1488804924.js:6未捕获的错误:[ng:btstrpd] http://errors.angularjs.org/1.6.2/ng/btstrpd?p0=%26lt%3Bdiv%20id%3D%22myApp%22%26gt%3B
编辑2:
都不是
var $ = jQuery;
var ErpkApp = unsafeWindow.ErpkApp;
function AddStyle(t) {
$("head").append("<style>" + t + "</style>");
}
(function() {
'use strict';
$("#sell_offers").after('<div id="myTest" ng-controller="MyController"> Hello {{greetMe}}! </div>');
ErpkApp.controller('MyController', [
'$scope', function ($scope) {
$scope.greetMe = 'World';
}
]);
})();
我使用主页的ErpkApp是因为<html ng-app="ErpkApp" lang="en">
也
var $ = jQuery;
function AddStyle(t) {
$("head").append("<style>" + t + "</style>");
}
(function() {
'use strict';
$("#sell_offers").after('<div id="myTest" ng-controller="MyController"> Hello {{greetMe}}! </div>');
var app = angular.module('ErpkApp', []);
app.controller('MyController', [
'$scope', function ($scope) {
$scope.greetMe = 'World';
}
]);
})();
有效。
Edit3:
var $ = jQuery;
function AddStyle(t) {
$("head").append("<style>" + t + "</style>");
}
(function() {
'use strict';
$("#sell_offers").after('<div id="myTest"><div ng-controller="MyController"> Hello {{greetMe}}! </div></div>');
var app = angular.module('myApp', []);
app.controller('MyController', [
'$scope', function ($scope) {
$scope.greetMe = 'World';
}
]);
angular.bootstrap($('#myTest'), ['myApp']);
})();
userscript.html?id=bbb54573-b5ea-43c3-84eb-119847f9176d:4 ERROR: Execution of script 'game Inventory extras' failed! [ng:btstrpd] http://errors.angularjs.org/1.6.2/ng/btstrpd?p0=%26lt%3Bdiv%20id%3D%22myTest%22%26gt%3B
我想我必须放弃。我读到角度不允许嵌套应用程序。 html
主页已经被引导,因此我无法在下面附加任何新应用。