[Request] Submit html Sourcecode [solved]

in Ideas and script requests
Subscribe to [Request] Submit html Sourcecode [solved] 28 posts, 4 voices



Unimatrix_0 Scriptwright

Hi,

I'm searching/requesting a script for Greasmonkey that will read out the html-source-code of certain pages (BattleRepports of MMOG) and displayes a simple button at the bottom to submit.
On submit everthing between <body> and </body> should be send to my page as default value of a textarea with the name="kb" .
So the user only have to add name an pres submit to store the submited BattleReport.

Best regards

Un1matr1x

 
dob Scriptwright

var link = document.body.appendChild(document.createElement("a"));
with (link) {
    style.cssText = "position: fixed; top: 2px; left: 2px; padding: 4px; background: #fff; color: navy; border: 1px solid navy";
    href = "javascript;";
    addEventListener("click", function() {
        GM_xmlhttpRequest({
            method: "post",
              headers: {
                 "Content-Type": "application/x-www-form urlencoded"
             },
            data: encodeURIComponent("kb="+document.body.innerHTML),
            onload: function(e) { GM_log(e.responseText); }
        });
      }, false);
}

 
Unimatrix_0 Scriptwright

Hi dob,

thx for the fast reply ;)

I repleaced the "javascript;" with my page-link and tried it and it didn't work.

Maybe there's a problem to "understand" because this board changes to much, eaven with ^.-

Element to change and the sourcecode should be placed between the <textarea> </textarea>

thx 4 help

Best regards

Un1

 
JoeSimmons Scriptwright

It doesn't need to be in a textarea because it's easier to just submit the html without needing to put it in a useless textarea for now. The server you post that info to will still see it as coming from an element named "kb" so it shouldn't matter.
As for the url, what did you put?

 
Unimatrix_0 Scriptwright

I want to get it into the textarea beacause the user should be able to choose the options he want to and also fill the Names-Field.

the url i set in is Store your BattleReport

Best Regards

Un1

 
JoeSimmons Scriptwright

It probably didn't work because the other input fields need to be filled too.
So why not just have a link you can click, then it asks the username and submits?

 
Unimatrix_0 Scriptwright

Sounds not that bad :)

But I thought:

a) it might be easier to build the script
b) the user can also choose the other options (title, skin f.e.)
c) you can see if your aren't logged in and log in if you want

So I requested the script as I did, but any working script would be great and I would be happy about it ;)

 
Mikado Scriptwright

var link = document.body.appendChild(document.createElement("a"));
with (link) {
    style.cssText = "position: fixed; top: 2px; left: 2px; padding: 4px; background: #fff; color: navy; border: 1px solid navy";
    href = "#";
    textContent = "Send";
    addEventListener("click", function() {
        GM_xmlhttpRequest({
            url: "http://kb.un1matr1x.de/save.php?lang=en",
            method: "post",
            headers: {
                 "Content-Type": "application/x-www-form-urlencoded"
            },
            data: "username=YOURUSERNAME&userally=&titel=" + encodeURIComponent(prompt('Title:') || 'TITLE') + "&privat_kb=false&time=false&koord=false&tech=false&style=0&kb=" + encodeURIComponent(document.body.innerHTML),
            onload: function(e) {
				GM_openInTab('http://kb.un1matr1x.de' + e.responseText.match(/<a href="\.(.+?)"[^>]+>Directlink for the BattleReport<\/a>/)[1]);
			}
        });
      }, false);
}

 
Unimatrix_0 Scriptwright

Thanks Mikado,

your script is working great ;)

But I have two question (sry 4 that):

Is it possible to open the url also and transmite then the data, because after submit them you normaly get a lil' text how you can find your submited report and how you can share this.

And the second question:
Any hint how to make this?

So why not just have a link you can click, then it asks the username and submits?

 
Mikado Scriptwright

Edited code above.

 
Unimatrix_0 Scriptwright

thx :)

working Great

 
Unimatrix_0 Scriptwright

Hi,

it's me again ^.-

the script itself works fine, I use:

// ==UserScript==
// @name           KB-Hosting
// @namespace      KB-Hosting
// @include        http://uni*.ogame.*/game/index.php?page=bericht&*&bericht=*
// @include        http://uni*.ogame.*/game/index.php?page=combatreport*
// ==/UserScript==

var link = document.body.appendChild(document.createElement("a"));
with (link) {
    style.cssText = "position: fixed; bottom: 2px; left: 2px; padding: 4px; text-decoration:none; color:#f1f1f1;font: 12px Verdana,Arial,SunSans-Regular,Sans-Serif;text-align:center; background:url(http://kb.un1matr1x.de/images/icons/hauptnavi_a.gif) no-repeat;height:29px;width:135px;"
    href = "#";
    textContent = "KB Speichern";
    addEventListener("click", function() {
        GM_xmlhttpRequest({
            url: "http://kb.un1matr1x.de/save.php",
            method: "post",
            headers: {
                 "Content-Type": "application/x-www-form-urlencoded"
            },
            data: "username=" + encodeURIComponent(prompt('Username:') || 'USERNAME') + "&userally=" + encodeURIComponent(prompt('Alliance:') || 'USERALLY') + "&titel=" + encodeURIComponent(prompt('Title:') || 'TITLE') + "&privat_kb=false&time=false&koord=false&tech=false&style=0&kb=" + encodeURIComponent(document.body.innerHTML),
            onload: function(e) {
				GM_openInTab('http://kb.un1matr1x.de' + e.responseText.match(/<a href="\.(.+?)"[^ >]+>Direktlink zum Kampfbericht<\/a >/)[1]);
			}
        });
      }, false);

and after store a BattleRepport I've got "KB Speichern" at the bottom, because that's the Script-Button. Can I prevent this?

And if I'm allowed to be impertinent, somebody might tell me how to make a radio-button input where you can select the "true/false" for the other attributes.

But again I have to: Thx for any help provided here (and your answers are so damn fast)

 
JoeSimmons Scriptwright

Unimatrix_0 wrote:
and after store a BattleRepport I've got "KB Speichern" at the bottom, because that's the Script-Button. Can I prevent this?
I don't get what you mean. You don't want the link there after you submit it or what?

Mikado, you shouldn't add an element to the page then edit it, it's slower to access the page every time instead of editing it locally then adding it.

Unimatrix_0 wrote:
And if I'm allowed to be impertinent, somebody might tell me how to make a radio-button input where you can select the "true/false" for the other attributes.
That would require making a form and adding it to the page and all that... I just made some code to give you an ok/cancel (ok=true, cancel=false) box instead of the radios. http://pastebin.com/f575c6309
 
Unimatrix_0 Scriptwright

and after store a BattleRepport I've got "KB Speichern" at the bottom, because that's the Script-Button. Can I prevent this?
I don't get what you mean. You don't want the link there after you submit it or what?

The Button-Name link.textContent is also stored at the end of the page f.e. HERE . If you scroll down at the end you can see "KB Speichern" what ain't normaly there.

---
Your edition of this script looks good, but has a lil bug - it adds to much to the url thats open in a new tab f.e.:

http://kb.un1matr1x.de/kb.php?show=4844&pw=54d1...=

instead of:

http://kb.un1matr1x.de/kb.php?show=4844&pw=54d1dc

so you will get the error-message:

Information

The choosen BattleReport is "privat" and needs a password, which was not entered correct.

 
JoeSimmons Scriptwright

Hmm try this: http://pastebin.com/f51c42d7a

 
Unimatrix_0 Scriptwright

I'm sorry to tell, but now it doesn't even open the url and still has the "KB Speichern" stored also

 
Unimatrix_0 Scriptwright

Hi,

it's Unimatrix - again.

After a lot Try&Error i found out what who it won't went wrong and work - only the "KB Speichern" at the end is still "alive" but i have an idea how to get ride of it. The "only" problem with this solution is i don't know how to make it. ^.-

Is it possible to store the html-sourc-code in a var befor adding the submit-button and use the var to be send to my website?

the script is now like: http://pastebin.com/m510113bd

ps: the error is the multi-language-part of my site so i have to force one language with ?lang=de in the url so the searched text after the href=" is found ;)

 
JoeSimmons Scriptwright

Oh, the submitted code includes the link from the script you mean? Try this... http://pastebin.com/f7e1eca6c
It removes itself when you click it, and before it grabs the html.

 
Unimatrix_0 Scriptwright

thx man

with

    link.addEventListener("click", function(e) {
			e.currentTarget.parentNode.removeChild(e.currentTarget);
        GM_xmlhttpRequest({

will it work perfect

thanks @ll, specialy JoeSimmons

 
Unimatrix_0 Scriptwright

Hi,

after a lil' testing i made some changes to provide the script in several languages. Now my Question is, if (and how) i can improve the performace of the script:

http://pastebin.com/m2cb283cd

 
JoeSimmons Scriptwright

I see you use a ton of space with the languages. What I would do is make a JSON object (even though switch might be technically faster, json will be shorter).
This is an example of how I would start, hopefully you can see how to do the rest of the languages since I only did en and de.
http://pastebin.com/f41e3452d
I left your old lang code commented so you can adapt, and I changed your for loop. Way too much space being wasted, hard to read. You don't need brackets around one command, and you can have it right after the if statement.

 
Mikado Scriptwright

Having big object with unused data actually looks worse than conditional declarations. I'd just replace if's with switch.

 
JoeSimmons Scriptwright

I think it looks good, JSON is quick. I don't like to have a ton of vars, slows things down.

 
Unimatrix_0 Scriptwright

thx 4 your great help ;)

i made the changes you said and thats what's the result:

http://pastebin.com/m113e9162

If i think of yesterday i didn't even understand anything around GM-Scripts (only how to use *gg*) but now i know a lil' bit - that's the best out of this here ;)

(and my users can easier my hosting-service)

so all what left to say:

thanks again

€dit: it was heavy to find out that I have to put a , between 2 languages ^.-

 
JoeSimmons Scriptwright

You're welcome. One more small optimization that could be made, use switch instead of if in the beginning where you have this:

if(Sprache=='org') Sprache='us';
if(Sprache=='info') Sprache='de';
if(Sprache=='com.es') Sprache='es';
if(Sprache=='onet.pl') Sprache='pl';
if(Sprache=='com.tr') Sprache='tr';

switch() executes about 15% faster and breaks down to simpler code in asm, so do this:
switch(Sprache) {
case 'org': Sprache='us'; break;
case 'info': Sprache='de'; break;
case 'com.es': Sprache='es'; break;
case 'onet.pl': Sprache='pl'; break;
case 'com.tr': Sprache='tr'; break;
}

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel