Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Questions] Window title! + couple extras #59

Closed
lilgandhi1199 opened this issue Sep 27, 2021 · 8 comments
Closed

[Questions] Window title! + couple extras #59

lilgandhi1199 opened this issue Sep 27, 2021 · 8 comments

Comments

@lilgandhi1199
Copy link

lilgandhi1199 commented Sep 27, 2021

Firstly. I would really love to have the script get access to the window title!
"Imgur | The Magic of the Internet"
... for example

Are there docs I could research this stuff?
window.crmAPI.GM.GM_setClipboard(location.href);
This is a beautiful example that got me the address of the current image instead of the link the image points to
and you showed us how to put variables in the clipboard which is AMAZING!
But I could stay out of your hair maybe these are just regular google chrome code that I could read about somewhere?

[LONGSHOT Last Question]
I am sending parameters to a program using 3 underscores as a delimiter.
window.open(media://${crmAPI.contextData.target.src}___${location.href}, '_blank');
I have my registry set to pass "%1"
Is there a way actually to pass them separately so they arrive to my program more safely.
???Possibly I would add %2 under the registry and then change '_blank' in that line? Or add something else?
Is this possible?

@lilgandhi1199 lilgandhi1199 changed the title [Questions] 3 Questions! [Questions] Window title! + couple extras Sep 27, 2021
@SanderRonde
Copy link
Owner

Answering your first question, you can just use document.title.

2nd question: Luckily this is indeed just regular javascript, so just reading up on javascript will teach you a lot of this stuff. W3schools is a decent resource for getting into the basics, but there's probably lots of resources around the internet. Stuff that's got crmAPI in it is generally exclusive to this extension (so there won't be any resources on it), but any javascript code will run in this extension as well.

3rd question: I'm not entirely sure, but I'm pretty sure you can just add %2 in the registry (like you suggested) and pass the second parameter either after a space (so window.open(`media://${crmAPI.contextData.target.src}___${location.href} ${nextArgument}`, '_blank');) or a comma (so window.open(`media://${crmAPI.contextData.target.src}___${location.href},${nextArgument}`, '_blank');). Not 100% sure but one of these might work. If that doesn't work, check out this section of the wiki. Using the python script you can customize the parameters it passes a bit more easily.

Let me know if you have any more questions, I could imagine the last question one is a bit hard to get working.

@lilgandhi1199
Copy link
Author

Yeah I tried a couple syntaxes. The first one I tried already like you said that seemed it might work was spaces.

window.open(media://${crmAPI.contextData.target.src}/&${location.href}&tips, '_blank');
window.open(media://${crmAPI.contextData.target.src}+${location.href}+tips, '_blank');
window.open(media://${crmAPI.contextData.target.src},${location.href},tips, '_blank');

Closing quotes sooner
window.open(media://${crmAPI.contextData.target.src}',${location.href},tips, '_blank'); window.open(media://${crmAPI.contextData.target.src}', '_blank', ${location.href});
Putting them after the blank

These last 2 actually crashed the whole extension it seems lol

@lilgandhi1199
Copy link
Author

But I can see you are just using "/" as delimiter which is fine. I'm good to go in that regard.
document.title worked thank you.

I'll have to write a javascript now to find like the artist for example on a pixiv illustration. And then send it along to be stored as METADATA. This is gonna organize so much.

https://www.pixiv.net/en/artworks/91575168

This is a perfect example of something quite easy to do with javascript right? It can search through entire HTML and so forth and pull bits of data like that?

@SanderRonde
Copy link
Owner

Good to hear it worked. Yep you're right, that's something that javascript is perfect for.

@lilgandhi1199
Copy link
Author

I'm figuring it out. Pretty great.
Thanks

@lilgandhi1199
Copy link
Author

lilgandhi1199 commented Oct 4, 2021

@SanderRonde
Why will none of these pull the list of HTML elements for me to sort through and identify which data I need?

const matches = document.querySelectorAll();
alert(matches.length + ' nodes inside this page');
for (let i = 0; i < matches.length; i++) {
alert(matches[i]);
}

var nodeList = document.getElementsByTagName();
var i;
for (i = 0; i < nodeList.length; i++) {
alert(nodeList[i]);
}

var list = document.getElementsByClassName();
for (let item of list) {
alert(item.id);
}

==========================================================
I at-least can see the functions of the API here so that's opened some doors.
Doing the same with document actually gives me every HTML element right?

for (const prop in crmAPI) {
// prop contains the name of each property, i.e. 'code' or 'items'
alert(prop);
// consequently, data[prop] refers to the value of each property, i.e.
//alert(crmAPI[prop]);
// either 42 or the array
}

@SanderRonde
Copy link
Owner

Why will none of these pull the list of HTML elements for me to sort through and identify which data I need?

They each require an argument to be passed. For example document.getElementsByTagName requires you to pass a tag name as the argument to search for. For example document.getElementsByTagName('img') gives you all image elements on the page. If you really want to find all elements on the page, you can do document.querySelectorAll('*') (this is quite inefficient and slow but it's a lot easier than the better alternative). I also wouldn't recommend looping through each of them and alerting them since there are going to be a lot of matches. Running document.querySelectorAll('*') on this page returns about 2700 matches. Instead of putting the javascript code in a script and running it like that, it's a lot easier to just go to the page, opening the developer tools (press F12), going to the console tag and putting the code in there. Then just pressing enter immediately executes it and you'll be able to have a look at it.

The best course of action for then finding a single element (like the author's name you mentioned before) on a webpage is to open the developer tools, find the element that contains the author's name, get its ID or class and use getElementById('thatId') to find the element. With a bit of luck that will work.

I at-least can see the functions of the API here so that's opened some doors. Doing the same with document actually gives me every HTML element right?

No that will just show you all functions and properties that the document element has. Running document.querySelectorAll('*') shows you all elements.

for (const prop in crmAPI) {
// prop contains the name of each property, i.e. 'code' or 'items'
alert(prop);
// consequently, data[prop] refers to the value of each property, i.e.
//alert(crmAPI[prop]);
// either 42 or the array
}

First of all I'd recommend replacing alert with console.log. That will show you the value in the console tab of the developer tools in a lot more user-friendly way. Alert is really only meant for text and isn't a good fit for debugging. Second you can just call console.log(crmAPI) to explore all properties and their values in the console. It will give you a nice tree view. Alternatively you can run console.dir(crmAPI) to do sort of the same thing. The difference is console.dir will display everything as a tree-view, whereas console.log will show for example strings as just their text.

See this page for more info on how the console and stuf works

@lilgandhi1199
Copy link
Author

Okay sorry. I figured some of that out last night but forgot to post back.
I really appreciate it. Obviously early on everything is quite exciting and you learn a lot very fast.
I try not to bug you too much. Thank you for your clarification.

I have twitter storing their @handles_image48756.jpg automatically now and fixed a lot of website downloads by finding referrer URL and passing it to the CURL request. Might figure out how to feed that cookie too :P lol
If you know how and what I mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants