Hi. Thanks very much for writing this, Chris. Unfortunately, it doesn't seem to be working for me. Any idea how I can troubleshoot it? I have Firefox version 80.0 which is apparently the latest. Should I be getting a dialogue box for which I have to click OK? Thanks, Sean
On Monday, 31 August 2020 at 10:19:55 UTC+1 LWChris wrote: > 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 > Am 26.08.2020 um 23:44 schrieb Sean Smith: > > Hi, > > I'm trying to make a script so that when something on eBay needs to be > sent first class, I get some kind of warning when viewing the address label > page. The relevant part of the HTML is this: > > <div class="buyer__info__items"><h3 > class="buyer_info__header"><span>Selected</span></h3><span > class="buyer_info__secondary buyer__paid-service">Royal Mail 2nd Class > Letter / Large Letter</span></div> > > I need to make it so that when it says "1st Class", I get a pop-up or the > background of that section flashes yellow or something. > > I found this on StackExchange: > var searcharea = jQuery('h2').parent('div').text(); var searchstring = > "superstring"; if( searcharea.indexOf( searchstring ) != -1 ) alert("exchange > alert to your own things"); > > If I change h2 to h3 and "superstring" to "1st Class", I figured I'd get a > warning but that doesn't work. Could anyone please tell me if they know > what I'm doing wrong? Thanks! > > The entire script is: > > // ==UserScript== > // @name eBay order first class postage alert > // @include https://gslblui.ebay.co.uk/gslblui/new_label?* > // @version 1 > // @grant none > // ==/UserScript== > var searcharea = jQuery('h3').parent('div').text(); > var searchstring = "1st Class"; > if( searcharea.indexOf( searchstring ) != -1 ) > alert("Send this item first class"); > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/greasemonkey-users/15397ce4-8285-4f19-a4db-c973568a921an%40googlegroups.com > > <https://groups.google.com/d/msgid/greasemonkey-users/15397ce4-8285-4f19-a4db-c973568a921an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/greasemonkey-users/b779ee04-f568-4ffe-9641-1b898ad8eb52n%40googlegroups.com.
