Greasemonkey script to replace text in html [duplicate] - greasemonkey

This question already has answers here:
How to relink/delink image URLs to point to the full image?
(2 answers)
Closed 7 years ago.
i want to make Greasemonkey script to replace text in html like this:
<img src="http://example.com/image.jpg" data-gifsrc="http://example.com/image.gif">
to
<img src="http://example.com/image.gif">
in website thechive.com
please help me, thanks.

While I cannot find the data-gifsrc attribute on the mentioned website, youi cannot assume the JQuery would be present and available for Greasemonkey.
// attribute name
var attrName='data-gifsrc';
// list all images
var imgs=document.getElementsByTagName("img");
// loop every images
for(var i=0;i<imgs.length;i++) {
// check for attribute
if(imgs[i].attributes[attrName]) {
// set image source
imgs[i].src=imgs[i].attributes[attrName].value;
// remove attribute
imgs[i].attributes.removeNamedItem(attrName);
}
}

Related

I want to open this router link in a new tab instead of same tab [duplicate]

This question already has answers here:
How to open a new tab with router.navigate in TypeScript
(6 answers)
Closed 2 years ago.
This is my function which directs to the page route
.ts file
readmoreFunc(data:any){
this.showId = data._id;
this.contentType =data.type
this.router.navigate(['/dashboard/dashboard-content/', this.showId,this.contentType])}
showId and contentType are my params. for eg"(http://localhost:4200/dashboard/dashboard-content/ckhewcmcj000v98t9zcb89rz0/Recent-Post) i want to open it in another tab in chrome.
Try this,
const url = this.router.serializeUrl(
this.router.createUrlTree([`/dashboard/dashboard-content/${this.showId}/${this.contentType}`])
);
window.open(url, '_blank');

Getting whole query param in node.js [duplicate]

This question already has answers here:
get url after "#" in express.js middleware request
(3 answers)
Closed 3 years ago.
I have an endpoint like this:
app.post('/sendCode', async (req, res) => {
const { code } = req.body;
});
And url like this:
http://localhost:3000/sendCode?code=ABCDEFG%##HIJKLMNOPRS
So when I enter this link in the browser I will trigger the endpoint. This works. However my code taken from req.body cuts out the second part of the code. So in my endpoint I see only ABCDEFG% part, the second is cut off. How can I get whole ABCDEFG%##HIJKLMNOPRS?
The browser won't send the part of the URL that starts with hash # symbol. The information that follows the hash (URL fragment) is intended for Javascript code executed by the client.
More on this topic here: Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?

Access window variable from Content Script [duplicate]

This question already has answers here:
Chrome extension - retrieving global variable from webpage
(5 answers)
Hijacking a variable with a userscript for Chrome
(1 answer)
Closed 9 years ago.
I have a Chrome Extension that is trying to find on every browsed URL (and every iframe of every browser URL) if a variable window.my_variable_name exists.
So I wrote this little piece of content script :
function detectVariable(){
if(window.my_variable_name || typeof my_variable_name !== "undefined") return true;
return false;
}
After trying for too long, it seems Content Scripts runs in some sandbox.
Is there a way to access the window element from a Chrome Content Script ?
One thing that is important to know is that Content Scripts share the same DOM as the current page, but they don't share access to variables. The best way of dealing with this case is, from the content script, to inject a script tag into the current DOM that will read the variables in the page.
in manifest.json:
"web_accessible_resources" : ["/js/my_file.js"],
in contentScript.js:
function injectScript(file, node) {
var th = document.getElementsByTagName(node)[0];
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', file);
th.appendChild(s);
}
injectScript( chrome.extension.getURL('/js/my_file.js'), 'body');
in my_file.js:
// Read your variable from here and do stuff with it
console.log(window.my_variable);

How to get image resolution data from uploaded image in express? [duplicate]

This question already has answers here:
Opening images on NodeJS and finding out width/height
(3 answers)
Closed 9 years ago.
I am using express 3 to make a http server which uploads the image in a designated folder but I am not able to get the image resolution in the req object .
I tried looking in req.files and req.files.images and req.files.headers but I could not find that information .
How can I get the resoultion of the uploaded image .
See solution here: Opening images on NodeJS and finding out width/height
var im = require('imagemagick');
im.identify(req.files.images.path, function(err, features){
if (err) throw err
console.log(features)
// { format: 'JPEG', width: 3904, height: 2622, depth: 8 }
})
Make sure you have imagemagick included and installed in your project.

calling Greasemonkey functions from web page [duplicate]

This question already has an answer here:
How to call Greasemonkey's GM_ functions from code that must run in the target page scope?
(1 answer)
Closed 8 years ago.
Can I call function() of my custom Greasemonkey from my page?
For example,
I created a GM script that contains do_this() function.
I want my-web-site.com call the do_this() function.
But I can't.
I know, I can by doing unsafeWindow.do_this() but doing so prevents
me from calling GM_xmlhttpRequest().
Any ideas?
here the example that working, first create element then addEventListener
// ==UserScript==
// #name GM addEventListener Function Test
// #namespace ewwink.com
// #description GM addEventListener Function Test
// #include http://*
// ==/UserScript==
document.body.innerHTML+='<input type="image" id="alertMeID" onclick="do_this()" style="position:fixed;top:0;left:0" src="http://i55.tinypic.com/2nly5wz.gif" />';
document.getElementById('alertMeID').addEventListener('click', do_this, false);
function do_this(){
alert('hello World!, today is: '+new Date())
}
I just had the same Problem. You can find good information here in the wiki. I would suggest to use script injection to insert the needed code into the document. That way it will run like its in the sourcecode of the page. You can't use GM_ functions there either but you can use a combination of script injection (to retrieve a variable for example) and classic greasemonkey scripting with all the GM_ functions (For example you could use the variables you read and POST them with GM_xmlhttpRequest()).
Furthermore, techniques like script injection have several security-related advantages over unsafeWindow.
I hope that helps.
Never used this myself but here is the workaround http://wiki.greasespot.net/0.7.20080121.0%2B_compatibility.
unsafeWindow.someObject.registerCallback(function() {
var value = "bar";
setTimeout(function() {
GM_setValue("foo", value);
}, 0);
});
No, GM_* functions are not accessible from webpage.

Resources