THIS IS A STATIC MIRROR OF USERSCRIPTS.ORG - LOGINS DO NOT WORK

Posts by Watilin

473 posts

Script development : Array in GM_Script

I was just giving the simpliest solution. Of course, if there are trouble with the commas, using JSON is more convenient. But isn’t that a too big hammer, granted that we know the object we work on is an array?

 

Script development : Changing Tab Sequence

Check this:

<!DOCTYPE html>  
<html lang=en>  
<head>  
   <meta charset=utf-8>  
   <title>Test with tab indexes</title>  
</head>  
<body>  
   <input tabindex="2"  value="2">  
   <input tabindex="1"  value="1">  
   <input tabindex="0"  value="0">  
   <input tabindex="1"  value="1">  
   <input tabindex="-1" value="-1">  
   <input tabindex="3"  value="3" disabled>  
</body>  
</html>
 

Userscripts.org discussion : Who installed my script

installing script with “blind eyes” is stupid…

You’d be surprised about how many people blindly trust the sole title of a userscript. I guess most of them aren’t even aware a script can be harmful. Most people don’t want to know how things work but just expect stuff to be magically done.

For the record, take a look at this: DoA Information Stealer

noone found my script until now. In few days my script was installed 8 times..

It seemed noone found your script until recently, but this is just because the install counter was broken.

Where I can find statictics about whose installs ? Who, where, from, via which browser, etc.

Having those intel would allow you to perform some kind of fingerprinting, and thus would jeopardize the user’s privacy. I don’t know if this is the reason USO doesn’t provide such stats, but this is my feeling anyway.

 

Script development : Array in GM_Script

With GM storage you can only serialize strings. What you can do is:

  • store a serialization of the whole array
  • work on a live, deserialized array
  • reserialize the array when you need it stored back

One way to serialize/deserialize an array is as simple as using toString and split.

["a", "b", "c"].toString()  =>  "a,b,c"  
"a,b,c".split(",")          =>  ["a", "b", "c"]
 

Userscripts.org discussion : Spam and malware

thenopicadsfan – sends unwanted PMs

 

Script development : Any help for a newbie? Simple script needs improvement.

Hi!

Well I’m arriving after the battle but, after reading the whole thread, I thought I could add my few cents.

TheDr:
redoing the script so that it waits until any of the above the above elements is present

There is a pattern I frequently suggest, I call it periodical check. It looks like this:

(function periodicalCheck( ){  
   if (someConditionVerified) {  
      doStuff();  
   } else {  
      setTimeout(periodicalCheck, 500);  
   }  
}());

I think this code is self-explanatory but here’s the idea:
first you define an auto-invoking function ((function(){ ... }()), see [IIFE](https://en.wikipedia.org/wiki/IIFE)).
In it, you check for a condition to be verified, and if it is, run your main code (the doStuff function). Else, you rearm the checking for the next 500ms. You can adapt this 500ms delay to your convenience.


any element whose ID begins with “ta_”

Do you know those two very useful functions querySelector and querySelectorAll? They allow you to select elements by CSS selectors. In CSS, the sentence “any element whose ID begins with “ta_"” becomes [id^="ta_"], so you only have to write:

document.querySelectorAll("[id^='ta_']");

Then you get a collection (a kind of array with less methods) and you can iterate over it to remove all of its items from the DOM — or better, simply hide it to avoid a reflow, as erosman and Joe suggested. (Talking about it, isn’t it visibility: hidden instead of visibility: 0?)

As a bonus exercise, since you seem to be eager to learn tricks, I’ll let you (re)discover array’s [forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) method. More, if you can ensure the browser uses at least JavaScript 1.6, you can even use a [generic Array method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Array_generic_methods) — but keep it for further reading.


I was told elsewhere that removing scripts from a page doesn’t work because the script has already executed by the time GM sees it.

That’s true. You only remove the source code, and this has no effect because it’s already been parsed.

I’m looking at other solutions

You can use [beforescriptexecute](https://developer.mozilla.org/en-US/docs/Web/Reference/Events/beforescriptexecute) events, with the disadvantage that it currently only works with Firefox. That’s what erosman did in his script.

By adding @run-at document-start you make your script run at the moment the page begins being parsed, as opposite to the DOMContentLoaded event which marks the end of parsing. Then you can listen (with [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener)) to beforescriptexecute events, and possibly cancel them to prevent the script from running. This is very powerful.

To determine wether to cancel the script or not, you have to check either its src attribute if it’s an external script, or its text content if it’s inline.


Finally,

JoeSimmons:
There’s a great article [here](http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/) about it.

Thank you Joe for this very interesting link.

 

Ideas and script requests : Simple? script for xHamster to see private videos

Here’s a bookmarklet. I rewrote it a bit to make it work with both http and https protocols, and to add basic URL checking. I think it’s necessary because a bookmarklet can be invoked onto any page.

javascript:void(function(){  
   var match = location.pathname.match(/^\/user\/([^?#]+)$/);  
   if (!match) {  
      alert("URL doesn't match!");  
   } else {  
      location = "/user/video/" + match[1] + "/new-1.html";  
   }  
}());

Here’s a minified version whenever there is trouble with the linefeeds:

javascript:void(function(){var m=location.pathname.match(/^\/user\/([^?#]+)$/);if(!m)alert("URL doesn't match!");else location="/user/video/"+m[1]+"/new-1.html"}());
 

Userscripts.org discussion : Cannot install some scripts "Error 503"

Already talked about: Error 503 Service Unavailable

 

Userscripts.org discussion : REPORT: Abbey Alicia HUNDREDS of fake scripts

Sadly such bot accounts with hundreds of scripts are legion.

Your help is appreciated, but didn’t you see there is a dedicated topic?

 

Userscripts.org discussion : Don't installs

Please refer to Error 503 Service Unavailable.

 

Script development : Userscript vs extension

As far as users pay :)

ugly buggy ecosystems like firefox

Are you trolling?

 

Script development : Userscript vs extension

[email protected] wrote:
stupid users

Will you spend your life making software for an idealistic, nonexistent audience of “smart” users, or rather develop for the most people? You have to accept the world as it is.

Either tell your users to install a userscript manager then your script, and so much for those who are too “stupid” or who don’t want to do it; or develop an extension for them, doing your best to make a secure and stable product.

Remember that the software must adapt to the user, not the opposite.

 

TRUSTED Facebook 100,999+ Followers in 24 hours Trusted 05/04/2014 : Not working

You got scammed. This script is malicious.

Uninstall it and change your Facebook password.

 

Userscripts.org discussion : USO prevent spammers - feature request

Check http://userscripts.uservoice.com/forums/795-general

 

Script development : run one command after the page loaded on soundcloud

I don’t get it. Are you talking about spinning?

I forgot to mention the most important: with JavaScript, using a while loop in order to wait for something consumes all of the main thread CPU, and this has great chances to freeze the UI.

 

Script development : run one command after the page loaded on soundcloud

I don’t know Soundcloud well but I tried to help you anyway. I went on the homepage and played a song, then typed $(".player") this into my console. There isn’t such element in the page. Maybe one needs to be logged in?

Note that with Greasemonkey, userscripts are run at the load event by default, so you don’t need to listen to this event. You can make your userscript run even earlier if you put a @run-at document-start directive — but that won’t help in your case because I think the player element is injected into the page after the load.

If the element actually does exist, my best bet is to wait for its injection. There are several ways to do that. In any case, [don’t use a while loop](http://en.wikipedia.org/wiki/Busy_waiting). If you don’t need to be accurate, the easier implementation is a setInterval or a recursive setTimeout. If on the opposite you need to run as soon as possible, use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver).

 

Script development : Scriptupdate causes new script version

Well, didn’t know about this one :)

 

Script development : C&C TA Scripts HELP!!!

Only a game admin is able to check IPs. A userscript can’t help because, by design, it uses informations provided by the server (typically HTML & JS code), and the server won’t provide players' IPs for obvious reasons of privacy.

 

Script development : Scriptupdate causes new script version

Can someone tell me how to quote? :x

Personally I use Markdown and the quoting symbol is a > at the beginning of a paragraph. (See this [markdown playground](http://daringfireball.net/projects/markdown/dingus).)

Alternatively, with the HTML syntax, use the < blockquote > tag.

Most people in this thread seem to be using Sizzle’s Userscripts Comment Fix.

 

Script development : Trying to fix an abandoned script. Can someone help me with a simple regex replace?

+1 to Jefferson. I don’t buy a word about this “drive” and I don’t know where you could have read about it Erosman. Luckily the philosophy of USO is at the opposite side of it.

For example, look for USO spam killers scripts and you’ll find that many of the most active members of this site have authored their own.

 

Script development : Write a variable to a file in Javascript

[GM_getValue](http://wiki.greasespot.net/GM_getValue)

but I want to get the value of “foo” into a variable.

There,

var myVariable = GM_getValue("foo");

is precisely the answer to your question. But perhaps you didn’t want to ask that question.


Maybe this will help you:

In the doc you can find that GM_getValue accepts an optional second argument, which is taken as a default value. Example:

var myVariable = GM_getValue("foo", "defaultValue");

In the event there isn’t any "foo" entry in the storage, myVariable receives the string "defaultValue".

 

Script development : error

Please refer/report to https://userscripts-mirror.org/topics/214463

 

Userscripts.org discussion : 413 Request Entity Too Large

It seems that some improvements are being made on this site.
Some errors are popping — we’re currently experiencing 413, 503 and maybe others, I can’t tell.

Better be patient :)

 

Script development : Scriptupdate causes new script version

I have had issues with GM crashing before (GreaseMonkey Misbehaving) and it is possible that it was the reason.

You’re cursed.

 

Userscripts.org discussion : 413 Request Entity Too Large

I guess it means that the file you’re trying to upload is too large… Didn’t the site specify a maximum file size?