Merge lp:~mcintire-evan/launchpad-gm-scripts/fix_button_tags into lp:launchpad-gm-scripts

Proposed by Evan McIntire
Status: Merged
Merged at revision: 181
Proposed branch: lp:~mcintire-evan/launchpad-gm-scripts/fix_button_tags
Merge into: lp:launchpad-gm-scripts
Diff against target: 62 lines (+21/-8)
1 file modified
lp_buttontags.user.js (+21/-8)
To merge this branch: bzr merge lp:~mcintire-evan/launchpad-gm-scripts/fix_button_tags
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+281559@code.launchpad.net

Description of the change

Fix lp_buttontags.user.js

At some point, GM_ functions began needing special permissions to run, which involved adding
    // @grant <function>
to the UserScript header

This change allows the functions to run again, which makes the script work again

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

While the script reacts after I click a tag, the tag does not seem to be added to the bug report. Even after a second reload of the page I do not see the tag I clicked on. Have you tested this on a bug report? If so what version of firefox were you using?

Revision history for this message
Evan McIntire (mcintire-evan) wrote :

My bad, I didn't fully test actually adding the tags. Is there a place I could do testing without messing with any actual bugs?

Revision history for this message
Brian Murray (brian-murray) wrote :

staging.launchpad.net seems to be down but qastaging.launchpad.net should work. However, you'll need to modify the @include to qastaging which is a good improvement anyway!

182. By Evan McIntire

Inject post() into the page and run it to bypass Greasemonkey sandboxing

183. By Evan McIntire

Actually commit the code

184. By Evan McIntire

Revert back to actual tags file

Revision history for this message
Brian Murray (brian-murray) wrote :

This works for me and it is possible to add tags again with this script. Thanks!

Revision history for this message
Brian Murray (brian-murray) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lp_buttontags.user.js'
2--- lp_buttontags.user.js 2013-05-13 15:46:00 +0000
3+++ lp_buttontags.user.js 2016-01-06 02:48:10 +0000
4@@ -4,6 +4,9 @@
5 // @description (Launchpad) Buttons for adding tags
6 // @include https://bugs.launchpad.net/*/+bug/*
7 // @include https://bugs.staging.launchpad.net/*/+bug/*
8+// @grant GM_getValue
9+// @grant GM_setValue
10+// @grant GM_xmlhttpRequest
11 // ==/UserScript==
12
13 // Feature Wishlist:
14@@ -42,12 +45,22 @@
15
16 // uses Launchpad javascript client to add data to bug tags
17 function post(data) {
18- var lp_client = new LPJS.lp.client.Launchpad();
19- var bug = new LPJS.lp.client.Entry(lp_client, LP.cache.bug, LP.cache.bug.self_link);
20- bug.set('tags', data);
21- bug.lp_save({on:{success:
22- window.setTimeout(function() { window.location.reload() }, 3000)
23+ //Very hacky way to work with Greasemonkey
24+
25+ //This function is injected and run in the context of the page, rather than the one Greasemonkey is in
26+ function injected(data) {
27+ var lp_client = new LPJS.lp.client.Launchpad();
28+ var bug = new LPJS.lp.client.Entry(lp_client, LP.cache.bug, LP.cache.bug.self_link);
29+ bug.set('tags', data);
30+ bug.lp_save({on:{success:
31+ window.setTimeout(function() { window.location.reload() }, 3000)
32 }});
33+ }
34+
35+ //Injects the above function into the page
36+ var script = document.createElement('script');
37+ script.appendChild(document.createTextNode('('+injected+')(["'+data.join('","')+'"])'));
38+ (document.body).appendChild(script);
39 }
40
41 // Retrieves url using HTTP GET, then calls the function cb with the response text as its single argument.
42@@ -238,7 +251,7 @@
43 return;
44 }
45
46- tags_current_list[tags_current_list.length] = this.id;
47+ tags_current_list.unshift(this.id);
48 post(tags_current_list);
49 // don't reload right away because the tag update post needs to finish
50 //window.setTimeout(function() { window.location.reload() }, 1200);
51@@ -281,8 +294,8 @@
52 }
53 else {
54 displayTags();
55- }
56+ }
57
58 }, false);
59
60-})();
61+})();
62\ No newline at end of file

Subscribers

People subscribed via source and target branches