Allegro.cc - Online Community

Allegro.cc Forums » The Depot » A.cc Javascript Extension

This thread is locked; no one can reply to it. rss feed Print
 1   2 
A.cc Javascript Extension
ImLeftFooted
Member #3,935
October 2003
avatar

I've finally finished my in-page edit extension for allegro.cc. To try it out, copy this text to your clipboard (ie control C):

1// Version 0.4.1
2function readCookie(name) {
3 var nameEQ = name + "=";
4 var ca = document.cookie.split(';');
5 for(var i=0;i < ca.length;i++) {
6 var c = ca<i>;
7 while (c.charAt(0)==' ') c = c.substring(1,c.length);
8 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
9 }
10 return null;
11}
12 
13function getHp(redirect) {
14 if (window.XMLHttpRequest) {
15 return new XMLHttpRequest();
16 } else if(window.ActiveXObject) {
17 return new ActiveXObject("Microsoft.XMLHTTP");
18 } else {
19 window.location.href = redirect;
20 }
21}
22 
23function onSubmit(editPageUrl)
24{
25 try {
26 var td = document.getElementById("tr-message");
27 var data = "body=" + escape(td.getElementsByTagName("textarea")[0].value);
28 
29 var hp = getHp();
30 
31 hp.open("POST", editPageUrl, false);
32 hp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
33 hp.setRequestHeader("Content-Length", data.length);
34 hp.send(data);
35 
36 var s = window.location.toString();
37 
38 var i = s.indexOf("forums/thread/") + "forums/thread/".length;
39 var i = s.indexOf("/", i);
40 
41 if(i == -1) i = s.length;
42 
43 var s2 = editPageUrl.substr(editPageUrl.indexOf("edit-post/") + "edit-post/".length);
44 
45 window.location = s.substr(0, i) + "/" + s2 + "#target";
46 window.location.reload();
47 }
48 catch(e) { prompt("ERROR", e); }
49 
50 // Block normal forum submit
51 return false;
52}
53 
54function loadEditor(idParm)
55{
56 var theId = "";
57 try {
58 theId = idParm.substring(5, idParm.length);
59 } catch(e) { alert("Error parsing post number from table's ID tag. Matt probably changed the HTML for forum posts on us!\nModify getEditPageData function to correct the problem.\n\nWe can't do a failsafe redirect w/o knowing the post ID"); }
60 
61 var theEditUrl = "/forums/edit-post/" + theId;
62 
63 try {
64 var hp = getHp(theEditUrl);
65 
66 hp.open("GET", theEditUrl, false);
67 hp.send("");
68 
69 var theTable = document.getElementById(idParm);
70 if(!theTable) throw "Unable to find table";
71 var target = theTable.getElementsByTagName("td")[1];
72 if(!target) throw "Unable to find target td";
73 target.innerHTML = hp.responseText;
74 
75 var divs = target.getElementsByTagName("div");
76 var theads = target.getElementsByTagName("thead");
77 
78 if(theads.length == 0) throw "Unable to find an 'theads'";
79 theads[0].innerHTML = "";
80 
81 for(var i = 0; i < divs.length; i++) {
82 if(divs<i>.id == "footer" || i == 2) {
83 divs<i>.innerHTML = "";
84 }
85 }
86 
87 var brs = target.getElementsByTagName("br");
88 
89 for(var i = 0; i < 3 && i < brs.length; i ) {
90 var parent = brs<i>.parentNode;
91 if(parent)
92 parent.removeChild(brs<i>);
93 }
94 
95 document.getElementById("btnPost").type = "button";
96 document.getElementById("btnPost").onclick = function() { onSubmit(theEditUrl); };
97 }
98 catch(e)
99 {
100 prompt("ERROR", e);
101 window.location.href = theEditUrl;
102 }
103}
104 
105function findPostsByMe()
106{
107 var postTags = new Array;
108 
109 postTags[0] = "edit-post";
110 postTags[1] = "forums";
111 postTags[2] = "allegro.cc";
112 
113 var myPosts = new Array;
114 
115 var thebody = document.getElementsByTagName('body')[0];
116 
117 var tables = thebody.getElementsByTagName('table');
118
119 for(var i = 0; i < tables.length; i++) {
120
121 var as = tables<i>.getElementsByTagName('a');
122 
123 for(var j = 0; j < as.length; j++) {
124
125 var postByMe = true;
126
127 for(k = 0; k < postTags.length; k++) {
128
129 if(as[j].toString().indexOf(postTags[k]) == -1) {
130 
131 postByMe = false;
132 }
133 }
134
135 if(postByMe) {
136 as[j].href = "javascript:loadEditor('" + tables<i>.id + "')";
137 }
138 }
139 }
140}
141 
142function onceLoaded()
143{
144 findPostsByMe();
145}
146 
147var giveupTimeout = 0;
148 
149function waitForLoad()
150{
151 var isDone = document.getElementById("forum_board");
152
153 if(isDone == null && giveupTimeout < 100) {
154 giveupTimeout++;
155 setTimeout("waitForLoad()", 150);
156 }
157 else {
158 onceLoaded();
159 }
160}
161 
162setTimeout("waitForLoad()", 150);

and then navigate to this page:
http://www.allegro.cc/cc/theme-css
And paste it into the lower javascript box.

You must be logged in to install the extension.

Indeterminatus
Member #737
November 2000
avatar

Testing ...

edit: Without having to read all the code through, what is it supposed to do?

edit 2: Now it seems to be working... Nice!

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

ImLeftFooted
Member #3,935
October 2003
avatar

Click the edit button on your post.

Btw, its only tested on FF so far.

X-G
Member #856
December 2000
avatar

That did absolutely nothing. Firefox 1.5.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

ImLeftFooted
Member #3,935
October 2003
avatar

Any errors reported? Where does your edit icon lead? Whats the roll-over address for your edit icon?

X-G
Member #856
December 2000
avatar

It leads to the same place it always has, and shows no relevant errors that I can see.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Jakub Wasilewski
Member #3,653
June 2003
avatar

Not only it does nothing on my FF 2.0 (no errors, and the usual edit link), but I also had a very hard time changing it back. For some reason, the Control Panel custom CSS dialog was loading for about 60 seconds, cycling back and forth between "Waiting..." and "Transferring..." in the status bar.

---------------------------
[ ChristmasHack! | My games ] :::: One CSS to style them all, One Javascript to script them, / One HTML to bring them all and in the browser bind them / In the Land of Fantasy where Standards mean something.

ImLeftFooted
Member #3,935
October 2003
avatar

If you roll the mouse over the edit icon do you get http://something/edit-post/### or do you get javascript:loadEditor?

X-G
Member #856
December 2000
avatar

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

ImLeftFooted
Member #3,935
October 2003
avatar

Did you refresh your cache? FF usually refreshes the js file after 3 consecutive reloads.

X-G
Member #856
December 2000
avatar

Throws an error I can't copy-paste (something about nodes), then opens the normal editor.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

relpatseht
Member #5,034
September 2004
avatar

The error reads, '[Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "http://www.allegro.cc/js/user.js/#### Line: 86"]'

Using FF 2.

ImLeftFooted
Member #3,935
October 2003
avatar

Ok Version 0.4 is ready to go! :D Should fix that error and a few others.

Matthew Leverton
Supreme Loser
January 1999
avatar

You should just make use of the RPC class.

ReyBrujo
Moderator
January 2001
avatar

So, what are you going to do with all our cookies?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

ImLeftFooted
Member #3,935
October 2003
avatar

Originally it was used to get the session cookie, until I realized it was already injected into the http header anyway. I just didn't get around to erasing it. I can't collect them because that would be cross-domain, which is impossible.

Has it actually worked for anyone yet?

@RPC, cool! Useful wiki page.

I see I should be using doc.add_onLoad instead of the setTimeout trick. I saw the onLoad stuff but couldn't figure out how to utilize it. *

*edit

Rampage
Member #3,035
December 2002
avatar

Edited by mistake...

-R

ImLeftFooted
Member #3,935
October 2003
avatar

Does your post change before you get the message box? If it does then version 0.4.1 should fix it.

Rampage
Member #3,035
December 2002
avatar

It works now, but I don't see the original text in the edit box.

-R

James Stanley
Member #7,275
May 2006
avatar

Testing.

EDIT:
Does absolutely nothing... No errors... :-/

EDIT2:
I may be able to explain why it's not working.
Are you testing in IE?
It seems to be requesting a Microsoft ActiveX control. I don't know if FF or Konqueror even support ActiveX, and it is even less likely that Microsoft's server will give it to them.
Note: I do not know JavaScript or ActiveX.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

It seems to be requesting a Microsoft ActiveX control.

IIRC, IE doesn't have dedicated support for the XMLHttpRequest object, it gets loaded on demand from a ActiveX control. Silly I know.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

I don't know if FF or Konqueror even support ActiveX,

They don't. Which is a good thing.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Michael Faerber
Member #4,800
July 2004
avatar

Quote:

and then navigate to this page:http://www.allegro.cc/cc/theme-css

This leads me straight to the main page of allegro.cc.

[EDIT]
Strange, works now.

[EDIT]
I pasted the text into the lower box that says "Custom JS", but it didn't change anything. What should be the changes?

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

GullRaDriel
Member #3,861
September 2003
avatar

Testing ...

I got the following error:

TypeError: document.getElementById("btnPost") has no properties

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Samuel Henderson
Member #3,757
August 2003
avatar

Quote:

This leads me straight to the main page of allegro.cc.

I noticed that after logging in the link took me to custom css and js page.

=================================================
Paul whoknows: Why is this thread still open?
Onewing: Because it is a pthread: a thread for me to pee on.

 1   2 


Go to: