Script Request: Put Alt with images
|
|
Maybe there is another (better?) way to do this, but i thought greasemonkey is the way to go.
My request:
Example:
I would like to specify for certain images of other sides an alternate description. The purpose of this: if you copy a page and paste it in notepad the images are lost. I don't think this will need a big script. If anyone can do it, would be very appreciated ! P.S. If you know another way to achieve this, not necessarily with greasemonkey, please let me know! |
|
|
i made it -> http://userscripts.org/scripts/show/11364 |
|
|
Thx a lot! Unfortunately it's not quiet doing what i wanted.
I would like it to be: something like
I would like to specify in that list which image get's which alt description. So that i can adjust it later. just that i don't know the right syntax to implement this because i don't know java at all.
|
|
|
What if (image = 32768.gif) or (image = iVBORw0KGgoAAAA.png) or (image = 8qGAyu7vPqfwFqGc.jpg)? |
|
|
var description = "";
for(var i=0; document.images.length > i; i++){
if(document.images[i].alt && document.images[i].alt != " ") continue;
description = ( document.images[i].title || document.images[i].src );
document.images[i].alt = description;
}
|
|
|
Or to get everything
var description = "";
for(var i=0; document.images.length > i; i++){
description = " - " + document.images[i].title + " - " + document.images[i].src;
document.images[i].alt += description;
}
|
|
|
@LouCypher. i know the image names so there won't be any 'random name' images. @Descriptor. Looks more like i need. Do you think this would work ? var description = "";
P.S. since i'm kinda new to greasemoney aswell can i couldn't find a HELP or a FAQ. How do i change a script? Adding it is not a problem. |
|
|
Yes, flip, that looks like it will work fine. But the title attribute isn't often used, it shows in a tool-tip when you mouse over an image. It used to be that alt was used for that which is improper, alt is meant for when no image is displayed, and is also used in place of the image when you Save as text or copy-all paste as text.
Now if you want to get "cow" out of the image name, well that's a more complex script that would probably require some regular expression to search the image src string, which is why I added it to "description". I actually find both scripts I wrote above useful because I sometimes want the image name, and without the script I have to go the extra step to Copy image to get the name. If you want to change someone else's script, you can Edit the script, but it would be better to save it under a new name and change the metadata, otherwise if you install the script again that will over-write all your changes. Also see the GreaseSpot Wiki |
|
|
To get just the name part of the image, you can add a regexp like this in the above code...
that's just off the top of my head, and assumes you know that the image has an extension such as ".jpg", and nothing after, no "?". Edited, think I made a mistake. |
|
|
Thx for your reply descriptor. Well actually i put in my code title because i thought it was the title for the filename. And i meant the filename. I can make some code but not java(script) so there is my little error. What would i have to put to look at the FILENAME rather then at the TITLE ? If i can grab the filename as a whole, im not sure if it needs regexp. But if you say it does then i believe you ;) Just to clarify once more Filename: XYZ.PNG -> ALT : something1
i'm not searching for a particular word in the filename.
P.S. The thing that confused me at first when i tried to edit a script i got an 'open file' dialog so i clicked cancel. but i didn't look at the window description that said: 'please select a text editor' |
|
|
So i figured the filename would be src. I tried to make it like this but it doesn't work var description = "";
Also i tried to do it with your suggestion with regexp: var description = "";
still no go. i know i'm getting close :P |
|
|
Yea, real close. I've been kinda busy and just popped in, but just remove the semi-colon (that is for end of command line)...
I think that'll work. |
|
|
Ah that's so sweet, just what i wanted. Thx a lot ! |
