Hi,
libraries like jQuery aren't accessible by default. You have to @require the jQuery library (from the Google Hosted Libraries https://developers.google.com/speed/libraries#jquery, for example), and then define it.
I always use a little "template" around my code to have a very
clean separation of what I am doing vs. the page's code, so they
don't interfere with each other:
// ==UserScript==
// @name Script name
// @version 1.0
// @author LWChris
// @include
// @require
https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
// Your constants here
var $ = jQuery.noConflict();
_addStyle = function() {
let style = $('<style type="text/css">\
</style>');
$("head").append(style);
};
_init = function() {
_addStyle();
// Your initializations here
};
// Your methods here
_init();
})();
Since your application is quite basic, you can remove the _addStyle method and its call. You can utilize the "load" event to run the check when the page is ready loading its content. Secondly, I'd try to make the jQuery selector as specific as possible.
So your script could look like this (I haven't tested it though since I don't use eBay):
// ==UserScript==
// @name eBay order first class postage alert
// @version 2
// @author Sean Smith
// @include https://gslblui.ebay.co.uk/gslblui/new_label?*
// @require
https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
const selector = ".buyer__paid-service";
// The element with the class name buyer__paid-service
const searchString = "1st Class"; // The content to
check for
const warningMessage = "Send this
item first class"; // The message
that'll be displayed
var $ = jQuery.noConflict();
_init = function() {
$(document).on("load", check);
};
var check = function() {
if (getSearchContent().includes(searchString.toLowerCase())
{
showWarning();
}
};
var getSearchContent = function() {
return $(selector).text().toLowerCase();
};
var showWarning = function() {
alert(warningMessage);
};
_init();
})();
Best regards
Chris
--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to greasemonkey-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/greasemonkey-users/15397ce4-8285-4f19-a4db-c973568a921an%40googlegroups.com.
Hi Sean,
yes, you can troubleshoot with these steps:
Feel free to report back your findings in case you get stuck.
Best regards
Chris
To view this discussion on the web visit https://groups.google.com/d/msgid/greasemonkey-users/b779ee04-f568-4ffe-9641-1b898ad8eb52n%40googlegroups.com.