w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to change var value in greasemonkey
If I understand you correctly, this should be an easy fix. You can simply overwrite the variable: So replace myInfo { "plusActive":true; } with plusActive = true; You shouldn't need to run any sort of a function, assuming the variable in question is not read until the page is loaded (which is far from certain).

Categories : Misc

How to change the default metadata in new Greasemonkey scripts?
I see you have already opened a feature request, which is the correct way to handle this long term. For a quick-and dirty, temporary fix -- that will work only for you and only until the next Greasemonkey update, you can do the following: Shut down Firefox. Find your Firefox profile folder. To be extra safe, save a backup copy of your profile folder. Find the Greasemonkey extension package. It will be in the extensions sub folder and is normally named {e4a8a97b-f2ed-450b-b12d-ee082ba24781}.xpi. Using a zip-file tool, like 7-Zip, open the .xpi file. Find and extract content ewscript.js. Just before line 124, script.push("// @version 1");, add the following lines: script.push("// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"); script.push("// @author

Categories : Jquery

Make Greasemonkey throw error on undefined variable
Unfortunately, Greasemonkey - and javascript in general, along with at least a few other non-compiled languages - do not give very good debugging errors... I can't count the number of times it tells me there is a missing ) at the end of an argument list that doesn't exist, and it turns out my error is elsewhere... When a script of mine won't run I add an alert after any value assignments and if they don't alert or alert the wrong data I have found the problem... for your example above I would debug by: this=self; alert(self); Although I would probably see the problem when I went to add the alert, but if I didn't notice - the alert either wouldn't pop up or it would have the wrong value... and if it didn't pop up, the error console would likely say self not defined.

Categories : Misc

Use Greasemonkey to change Text to Images (on a static site)?
I am not much of a userscript expert, but I had a script from here. The original site is down, but here's the script. // ==UserScript== // @name Inline Image Relinker // @namespace /web/20070712085327/http://www.sitzmar.com // @description Replaces links to images with the actual image // @include * // ==/UserScript== (function() { function getXPath(p, context) { var arr = new Array(); var xpr = document.evaluate(p,context,null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for(i = 0;item = xpr.snapshotItem(i); i++) { arr.push(item); } return arr; } doc = window.document; var xpath = "//A[(contains(@href, '.jpg') or contains(@href, '.jpeg') or contains(@href, '.gif') or cont

Categories : Javascript

Use Greasemonkey to change row format based on one cell's contents?
This one's a little easier than the linked example, I think. The key is understanding jQuery selectors and then using jQuery's .css() function. Assuming the page doesn't use AJAX, here's a complete script that works on the HTML you provided: // ==UserScript== // @name _Format the "not checked" rows // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ //--- The 'Not Checked' is case-sensitive var notChkdRows = $( "tr.dataRow:has(th.booleanColumn img[title='Not Checked'])" ); //--- Use whatever CSS you wish notChkdRows.css ( { "background":

Categories : Javascript

change value variable javascript if select field value change
Use a ternary operator to switch between 0 and .1 based on the select value var fees = ($("#select").val() === "cc" ? 0.1 : 0); You should wrap this in a function, and bind the select element to this function on change. e.g. : var sel = $("#select"); function setValue() { var total = 0, fees = (sel.val() === "cc" ? 0.1 : 0); // ternary $("#sub_total").val(total); $("#fee").val(fees); $("#sum").val(fees + total); // sum } setValue(); // call function sel.bind('change', setValue); // bind function to onchange of the select element

Categories : Javascript

replacing text between two strings in javascript using greasemonkey
The easiest way to do this would be with a regular expression. var comment = "[youtube]http://www.youtube.com/embed/XGSy3_Czz8k[/youtube]", match = comment.match(/[youtube]([^[]*)[/youtube]/); if (match) { var iframe = document.createElement("iframe"); iframe.src = match[1]; document.body.appendChild(iframe); }

Categories : Javascript

How can I submit this form properly with javascript/greasemonkey?
With jQuery you could submit this form like this: In this function you can process the data of the form. $(document).on("submit", "form", function(e){ e.preventDefault(); // get the data of the form var url = $(this).attr("action"), _csrf_token = $(this).find("input name=['_csrf_token']).val(); // jquery ajax call for example $.ajax( ); });

Categories : Javascript

Removing CSS Borders with javascript in greasemonkey/tampermonkey for facebook
border-right is a style property, not an element attribute, so removeAttribute won't work. Instead try this: document.getElementById("mainContainer").style.borderRight = "none"; (Note that border-right becomes borderRight for JavaScript, and make sure you spell names exactly.) However you might prefer user stylesheets. Browser extensions such as Stylish let you write CSS that is applied automatically, instead of going through script. (You can hide things using display: none, or mute them with opacity: 0.5.)

Categories : Javascript

Adding javascript to a XML file transformed with XSLT using a Greasemonkey script
Don't use onclick. This goes triple for userscripts, as there are additional scope and/or sandbox conflicts. Also, it's a poor idea to try and add JS into the XSLT file/text, and there is no need for script injection in this case either. Use the script to do whatever JS manipulation you have in mind. For example: // ==UserScript== // @name _XML Renderer with javascript functionality // @description Stylesheet and javascript for xml results // @include http://YOUR_SERVER.COM/YOUR_PATH/*.xml // @resource xslFile Q_17998446_transform.xsl // @grant GM_getResourceText // ==/UserScript== var xsl_str = GM_getResourceText ("xslFile"); var processor = new XSLTProcessor (); var dataXSL = new DOMParser ().parseFromString (xsl_str, "text/xml"); processor.importSty

Categories : Javascript

can't change the a variable value in the javascript function
The problem here is that the line starting with restler.get begins before the console.log, but it doesn't finish before it necessarily. You should put your console.log inside the restler.get call.

Categories : Javascript

How to change the value of a variable once per day in Java/javascript
Use Date and document.cookies to update your variable. Also i used two utility methods to manipulate document.cookies var today = parseInt(new Date().getTime()/(1000*3600*24)) var cookies = getCookies(); if(cookies["last_updated"] && cookies["last_updated"]<today) { /* update variable */ setCookie("last_updated", today, 1); } /* utility methods starts, adding utility methods to simplify setting and getting cookies */ function setCookie(name, value, daysToLive) { var cookie = name + "=" + encodeURIComponent(value); if (typeof daysToLive === "number") cookie += "; max-age=" + (daysToLive*60*60*24); document.cookie = cookie; } function getCookies() { var cookies = {}; // The object we will return var all = document.cookie; // Get all cooki

Categories : Java

Dynamically change and check variable in javascript
I don't like the way you do it, but the answer is to delete var before flag to make it global: flag = 0; proof EDIT if you want to prevent form submit your funct() must return false; maybe you try if(somethingIsOK){ echo "<script type="text/javascript">flag=1;</script>"; }else{ echo "<script type="text/javascript">flag=0;</script>"; } and again: it's a very-very bad idea to mix php and JS like that

Categories : PHP

how to change local variable in javascript by ajax?
The issue is that you run you if statement, and then set authenticated to true every time. It sounds like you are looking for an if else statement. function check_login(){ var authenticated = false; $.ajax({type:"POST",url:"/account/islogin/",data:"",async:false, success:function(data){ if(data=="null"){ signup(); authenticated = false; } else { authenticated = true; } } }); return authenticated; }; or even better, you can set up the authenticated to default to true and then only set it to false when the data is null. function check_login(){ var authenticated = false; $.ajax({type:"POST",url:"/account/islogin/",data:"",async:false, success:function(da

Categories : Javascript

How do I change a JavaScript variable value, inserted in a HTML document, using jQuery
Once document.write executes that code is finished. It isn't going to update based on des having a new value. What you can do is reassign it using $('#DESCRIPCION').text(). The first description will be populated, but any new data should be written using .text() (referencing the div to target) Changes around a bit to be more dynamic: <img src="http://placehold.it/100&text=Image1" data-desc="Image 1 description" /> <img src="http://placehold.it/100&text=Image2" data-desc="Image 2 description" /> <img src="http://placehold.it/100&text=Image3" data-desc="Image 3 description" /> <img src="http://placehold.it/100&text=Image4" data-desc="Image 4 description" /> <div id="DESCRIPCION"></div> And the JS: $(function(){ var $DESCRIPCION

Categories : Javascript

Android - Proper way to listen for variable change, and do something upon change?
You must set your variable via a setter method. Then, you can be reactive to that change. public void setMyVariable(int value) { this.myVariable = value; if (myVariable == 1) { doSomethingWhen1(); } else if (myVariable == 0) { doSomethingWhen0(); } } A more elegant way to do that will be an observer pattern, Here you can find more detailed documentation about it. You must certainly avoid while(true) loops on mobile device, it will drain your battery and you are also blocking the UI thread. That's the reason why your UI is unresponsive and your cellphone it's quite hot.

Categories : Android

js Change variable will affect to original variable
Objects are always passed around by reference. a and this.i refer to the exact same object. To get different objects, you'd need to just do this.i = {c:1}; or similar.

Categories : Javascript

ajax API call Variable {variable} - How do I change it
You need to build up the URL dynamically, based on each account parameter. You could use a small reusable function for that: function createEvent(account, eventData, callback) { var url = "/events/" + account + "/events"; $.ajax({ type: "POST", url: url, data: eventData }).done(callback); } Then, to use it: var event = { name: "Marcus", location: "HERE" }; // Get some_account_number from somewhere... createEvent(some_account_number, event, function(msg) { alert( "CREATE EVENT Data Saved: " + msg ); });

Categories : Javascript

Change global variable value with a local variable
There are 2 possible options: Change the 2nd parameter name (from blnUpgradeLocal to something else) in the function declaration Change the global variable value using window.blnUpgradeGlobal reference The former is better

Categories : Javascript

How would I remove a DIV if there are no IDs using Greasemonkey?
We might need to see the whole page to work out robust selectors for those <div>s. But, if they always contain iframes with src attributes to undesirable content, then you can use those iframes to hunt down the dastardly divs. Make a list of key text snippets in the bad iframe src attributes. I'm also using jQuery and waitForKeyElements(), in case this content is added by AJAX. So, the script looks something like this: // ==UserScript== // @name _Remove bad divs containing bad iframes // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a de

Categories : Javascript

Declaring a temporary variable into a global variable in javascript responseText
you're alerting before the test2 variable is filled with content (because of the XMLHTTPRequest needing some additional time to complete) var test2 = ""; function process(callback){ url = "http://www.example.com/example.html" var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { test2 = xhr.responseText; callback(); } } xhr.send(); } process(callbackFunction); function callbackFunction() { alert(test2); }

Categories : Javascript

How to set the swf path of TableTools when using it with Greasemonkey
If one examines the source code of dataTables.Tabletools.js, while initializing a datatable, tabletools uses the TableTools.DEFAULTS objects and combines them with your tables custom settings. At line no 1158 , as per the version (1.0.4-Tabletools2) that i have, the code sets the moviePath for ZeroClipboard_TableTools, which i am assuming, is a singleton. Now if you have multiple tables on the page, this object ends up taking the value of swfpath specified for the last table , or Default "sSwfPath": "../swf/copy_csv_xls_pdf.swf" , if not specified. /* Flash file location */ this.s.swfPath = this.s.custom.sSwfPath; if ( typeof ZeroClipboard_TableTools != 'undefined' ) { ZeroClipboard_TableTools.moviePath = this.s.swfPath; } So, i c

Categories : Misc

greasemonkey currency converter
You need to recurse or loop through just the nodes that have the dollar values. Never use replace() or RegExp on .html() or innerHTML. Not only will this trash the target page, but you will have a devil of a time getting the desired results. Recurse through the page using DOM methods. Note that currency values come in many formats, so converting them can get complex. Here's moderately robust code for the whole page (sans iframes) You can see it in action at jsFiddle: // ==UserScript== // @name _Global currency converter, dollars to rupees // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @grant GM_xmlhttpRequest // ==/UserScript== GM_xmlhttpRequest ( { method: "GET", url: 'http://rate-exchange.appspot.com/currency?from=USD&to=INR', //Google sends m

Categories : Javascript

GreaseMonkey @include for about:newtab
See the docs at "Include and exclude rules, Extra schemes". for a script to run on blank tabs, you must now explicitly set @include about:blank. For example: // ==UserScript== // @name _Very noisy script // @include about:blank // @include * // ==/UserScript== alert ("Fire on blank"); However, Firefox now uses about:newtab by default, and Greasemonkey currently doesn't consider about:newtab to be "Greaseable". (It should though, and I'll look into getting a pull-request accepted for this.) So, to get scripts firing on blank tabs, you currently must set those blank tabs back to using about:blank. Do that by opening about:config and setting browser.newtab.url to about:blank.

Categories : Javascript

Preventing pop-up box from being displayed using Greasemonkey
A Greasemonkey question is probably better asked over at userscripts.org Anyways... it seems like you just want to hide elements. CSS is probably the best way. There's a cool extension called Stylish that does this really well. Just use normal FF tools or Firebug to inspect what element pops up and try, using CSS rules, to hide it with Stylish. It's better that way, because dealing with Gmail using JavaScript could be really frustrating.

Categories : Javascript

how to assign a variable value to another variable instead of reference dojo javascript
You need to either do a deep clone of requiredStore (going through properties and prototype to create a perfect duplicate), or else just create a different memory store altogether: requiredStore = new Memory({ data:res }); temporaryStore = new Memory({ data: res }); I don't know why you wouldn't use this approach, but if you want to do a deep clone this question will help: Most efficient way to clone an object?

Categories : Javascript

can't pass php session variable to javascript string variable
First, like the comments have mentioned, make sure you're using the correct case of id, whether it's id or Id. Second, try using json_encode to convert it for javascript use. No need for "": var a = <?php echo json_encode($_SESSION['Id']); ?>;

Categories : PHP

How do I find out when a tab I've opened with greasemonkey is loaded?
I found a way around the problem... oddly enough, I couldn't do it when using GM_openInTab to create the window, but using mywin2=window.open("http://www.aywas.com/message/notices/9801049/", "my_win2"); allowed me to use the following code to detect the load and close the tab only after it was loaded enough for my purposes! (Although the 'window title' bit of that code above didn't seem to do anything...) mywin2.addEventListener('load', function() { mywin2.close() }, false);

Categories : Javascript

Convert a greasemonkey Script after E4x is not supported
If there is a dependency on e4x, try including the JavaScript implementation: e4x.js As an alternative, here are other questions which cover mapping e4x syntax to XPath or XML to JSON: What is the Flex/AS3/E4X equivalent of this xpath query? Howto convert E4X XML Elements into JSON Notation In addition, you can continue to use e4x by accessing the data via yql: Using e4x with yql

Categories : Javascript

Only target non-active buttons with Greasemonkey
Try this: waitForKeyElements ("a.action-button:not(.active)", triggerMostButtons); The first parameter here works like a jquery selector. It finds: "a" tags (a) with a class of "action-button" (.action-button) without a class of "active" (:not(.active)) Note that the "." character is CSS notation for a class identifier. Here's the jquery reference for "not": http://api.jquery.com/not-selector/

Categories : Javascript

How to use userscripts in a site?(How does Greasemonkey work)
Greasemonkey and Userscripts.org are meant to provide kind of lightweight extensions for the browser, not for the webpages. I.e. you install them as the user inside your browser. Some of the trivial scripts might be incorporated into webpages, but in general, Greasemonkey has some "superpowers" to do things that ordinary JavaScript can't do due to security constraints. For instance, issuing (and reading response of) cross-domain XMLHttpRequest, interactions between frames from different origin etc. Normally Greasemonkey scripts are executed when DOMContentLoaded is fired by the browser (this can be changed using @run-at directive to execute the script before anything is loaded). If the script has @grant none in its GM meta section, then it could be perhaps incorporated into your site, b

Categories : Javascript

greasemonkey simple string manipulation
var url = "www.something.com/item/4563/"; var matches = url.match(/item/(d+)/); var itemNumber = matches && parseInt(matches[1], 10); console.log(itemNumber); // => 4563

Categories : Misc

Including a Greasemonkey script across multiple domains
Reference: Greasemonkey Include and exclude rules Match Patterns Match patterns and globs The solutions that work on Greasemonkey (which is Firefox), may be different on Chrome and on Tampermonkey. Three basic approaches: Use 30 different @include lines: While this may be unpalatable in terms of cut-and-paste coding, it is the one approach that will work the same across browsers and the one that will have the best browser performance. The other approaches require the browser to do (more) checks against possibly every page or iframe visited. Use a regex @include: @include /^http://(1stDomain.com|2ndDomain.com|3rdDomain.net|etc.)/(admin/edit|blog|user/.+?/history)/ This is one line, and performs fairly well, but the line can get unwieldy, and this will only work on Greasemonkey an

Categories : Misc

Watch for element creation in greasemonkey script?
MutationObservers are called for more things than just adding nodes, including changes to attributes and removing nodes. So watch out for mutation.addedNodes returning null - in which case this code will fail. Try: if (mutation.addedNodes && mutation.addedNodes[0].getAttribute('class') === 'nav') { ... The mutation object also has a 'type' attribute that you can use to get more info; have you read the API docs on MDN? There are some good examples there.

Categories : Javascript

jQuery .ready not getting called from within Greasemonkey script
The alert doesn't fire for two reasons: The browser is redirected from www.ted.com to www.youtube.com right away -- long before the ready event can fire on ted.com. The script is not set to fire on youtube.com at all. If you want the script to fire on both domains, adjust the @include (or @match) directives and then use checks like: if (location.hostname == "www.ted.com") { var url = window.location.href; var talk_name = url.split("/").pop(); talk_name = talk_name.substring(0, talk_name.lastIndexOf('.html')); var youtube_search_url = 'http://www.youtube.com/user/TEDtalksDirector/search?query=' + talk_name; window.location.href = youtube_search_url; } to alter the script's behavior, per domain. Because @grant none is used, the GM script's jQuery c

Categories : Javascript

How can I save greasemonkey outputs across numerous tabs
Most UserScript environments provide the very useful GM_setValue and GM_getValue functions. You do have to be careful about race conditions though, so I would be tempted to have each tab generate a random number (perhaps based on time) and then put their stuff in a key based upon that value. Then, at the end, concatenate the strings together and display one large string at the end that can be cut-and-pasted. Or, if you'd rather not cut-and-paste, you can generate a massive string and use the HTML5 download attribute. Edit, based on OP's comment (Typed on the fly, untested.) // The documentation talks about the second parametere here -- a default value. var value = GM_getValue("value", ""); value += str + " "; GM_setValue("value", value); While all UserScript methods should underst

Categories : Javascript

Click many links, in one page, with a Greasemonkey script?
var all = document.getElementsByClassName("delete"); for(var i=0; i<all.length; i++) { var deleteUrl = all[i].href; var ifr = document.createElement("IFRAME"); document.body.appendChild(ifr); ifr.src = deleteUrl; } You could run a simple script like the above in the browser's JavaScript console or make it a bookmarklet.

Categories : Javascript

Calling a local WCF service via Scriptish or Greasemonkey
I figured out how to do it via a GET request thanks to M.Babcock for pushing me in that direction (unimportant parts intentionally left out to save space). Service.svc: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service : IService { [WebGet(ResponseFormat = WebMessageFormat.Json)] public bool MatchPartial(string partialFilename) { ... } } Web.config: <configuration> ... ... <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.webServer> <httpProtocol> <customHeaders> <!-- IMPORTANT FOR THIS TO WORK USING JQUERY GET OR AJA

Categories : C#

Greasemonkey script does not load external JS and CSS file
That linked answer was from 2011, and Greasemonkey has changed a lot since then. (Note, I just now updated that answer to reflect the changes.) Basically, you need to use @grant directives now. If you looked on Firefox's error console (CtrlShiftJ), you might have seen error messages like: GM_addStyle is not defined Here is a bare-bones addition of jQuery-UI to demonstrate the process: // ==UserScript== // @name _YOUR_SCRIPT_NAME // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js // @resource jqUI_CSS http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css // @grant GM_addStyle // @grant GM_getResou

Categories : Javascript

Can latest Tampermonkey / Greasemonkey still not use jQuery AJAX?
jQuery AJAX works fine with Tampermonkey and Greasemonkey, with only one limitation compared to jQuery use in a web page. For example, this cross-origin script works in both Tampermonkey and Greasemonkey: // ==UserScript== // @name _Demonstrate jQuery AJAX from Tampermonkey // @include http://stackoverflow.com/questions/18546180/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ $.ajax ( { type: 'GET', url: 'https://api.stackexchange.com/2.1/users/621338?site=stackoverflow&filter=!)2R0ltXnW6.fyPDiHJm', dataType: 'JSON', success: function (apiJson) {

Categories : Jquery



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.