Am 06.06.2013 09:37, schrieb Deckarudo:
Hi all,
I would like to know how to add an item to this list (a Flickr's menu):
[...]
And if it's possible, how to chose the location of the new item in the
list? I mean if I want it after the Sets entry?
Cheers!
Ithink the best approach is a combination of a selector, createElement
and insertBefore with parentNode and nextSibling.
Here's a possible way how to do it:
(function() {
// Select node to insert the new node after
var sets = document.querySelector("ul li a[data-track=You-sets]");
// Node not found, don't do anything
if (!sets) { return; }
// Create anchor element
var a = document.createElement("a");
// Set its attributes
a.setAttribute("data-track", "You-google");
a.setAttribute("href", "http://google.com/");
// Set the text (content)
a.appendChild(document.createTextNode("Visit Google"));
// Create the list item
var li = document.createElement("li");
// Set its class attribute
li.className="gn-subnav-item";
// Put anchor into list item
li.appendChild(a);
// Add the list item to the list by inserting it before the sets' next
sibling, i. e. after the sets
sets.parentNode.parentNode.insertBefore(li, sets.parentNode.nextSibling);
}());
The anonymous function is an easy way to make it work without any
additional code like listeners.
I tested the above, it works with @grant none.
It also works when add-ons like "NoScript" do not allow scripts for
flickr.com.
Greetings, Chris
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.