2010-06-26 4 views
1

저는 Javascript와 Greasemonkey에 완전히 익숙하지 않습니다. 비효율적이거나 잘못 수행하면 저를 바로 잡으십시오.동적 양식을 표의 끝에 추가하려면 어떻게합니까?

내가 게시하는이 포럼에서 "답장"버튼을 클릭하면 게시 할 텍스트 양식이있는 새로운 창이 열립니다. 응답 양식의 스크립트를 실제 스레드에 추가하는 그리스 몽키 스크립트를 만들고 싶습니다. 페이지.

그래서 프로그램은 토론을 저장하는 테이블을 통과하여 테이블 끝 부분에 childNode를 추가합니다. 그 childNode가 응답 페이지에서 작성된 양식이되기를 원합니다.

// ==UserScript== 
// @name QuickEeply 
// @namespace http://userscripts.org/users/181447 
// @description Adds "QuickReply" forms to TCC discussion posts 
// @include  * 
// ==/UserScript== 


var tables = document.getElementsByTagName("td"); 


for (var i = 0; i < tables.length; i++) { 

if (tables[i].className == "content") 
{ var editTable = tables[i]; 
} 

} 

editTable.appendChild = '' 

여기에 복사하고 "응답 페이지"에서 붙여 넣은 스크립트의

<form method="POST" action="http://dl.tccd.edu/index.php/classforums/posts/event=saveReply"> 
<input type="hidden" name="subject" size="45" id="txt_subject" maxlength="200" value=""> 
<br> 
Message:<br> 
<textarea rows="20" style="width:70%;" name="message" id="message"></textarea> 

<br> 
<br> 
<input type="submit" id="submit_post" value="Post Reply"> 
<input type="hidden" name="post_id" value="1010815"> 
<input type="hidden" name="thread_id" value="1010815"> 
</form> 

그래서 어떻게 스크립트를 만드는 방법에 대해 갈 수 있습니다 : 여기

내 스크립트의 골격이다 이 함수는 현재 페이지의 thread_id를 찾고 스레드가 실제로 위치한 페이지의 각 페이지에 대한 replybox를 만듭니다.

편집 : 다음은 소스 코드 -

http://pastebin.com/2UaUVGJA (주 토론 페이지)
http://pastebin.com/hAx2SPUu (응답 페이지)

편집 2 :

I've used Brock's template, and it's not working. What do I need to do to correct it? 

// ==UserScript== 
// @name   Quick_ReplyTest 
// @namespace  http://userscripts.org/users/181447 
// @description Inserts QuickReply 
// @include  * 
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js 
// ==/UserScript== 


/* Optional: 
window.addEventListener ("load", Greasemonkey_main, false); 
*/ 

$(document).ready (Greasemonkey_main); 


function Greasemonkey_main() 
{ 
    /*--- Get the first node inside the id="main" span (Google.com) 
     If that's not there, then get the first node of the html body. 
    */ 
    var TargetNode = $("a[href*='event=reply/post']"); 
    if (!TargetNode) 
     TargetNode = $("body *:first"); 


    $(TargetNode).after 
    (
     "<form method="POST" action="http://dl.tccd.edu/index.php/classforums/posts/event=saveReply"> 
     + "<input type="hidden" name="subject" size="45" id="txt_subject" maxlength="200" value="">" 
     + "<br> Message:<br>" 
     + "<textarea rows="20" style="width:70%;" name="message" id="message"></textarea>" 
     + "<br> <br>" 
     + "<input type="submit" id="submit_post" value="Post Reply">" 
     + "<input type="hidden" name="post_id" value="1010815">" 
     +"<input type="hidden" name="thread_id" value="1010815">" 
     +"</form>" 
    ); 
} 
+0

당신이보고있는 HTML을 보지 않고 말하기 힘든 종류입니다. Post ID와 Thread ID 변수를 사용할 수 있습니까? – desau

+0

소스 코드를 포함하도록 편집했습니다. – Parseltongue

답변

0

이동 this answer에 Greasemonkey 템플릿을 얻습니다.

특정 노드에 양식과 같은 HTML을 삽입하는 방법을 보여줍니다.

해당 샘플의 표 HTML을 양식 HTML로 바꿉니다. 그러면 TargetNode은 참조 페이지를 기준으로 $("a[href*='event=reply/post']")과 비슷합니다. 게시물 항목마다 양식을 삽입해야합니다.

경고 : 양식이 원하는 위치에 있지 않아도 각 양식에 아직 양식을 동기화하지 않았습니다.

할 수있는 일을하십시오. 그러나 첫 번째 부분을 작동시키고 동의율을 높이면 다음 단계는 새로운 질문으로 물어보아야합니다. ;-)

+0

감사합니다, 브록, 나는 당신을 나의 영원한 스승으로 선출합니다. – Parseltongue

+0

이 스레드에서 작성한 새로운 편집을 살펴보십시오. 지침을 따르지만 스크립트는 양식을 추가하지 않습니다. 나는 Jquery를 사용한 적이 없으므로 이해하지 못합니다. – Parseltongue

0

재 :

편집 2 : 나는 브록의 템플릿을 사용했습니다, 그리고 그것은 작동하지 않습니다. 문제를 해결하려면 무엇을해야합니까?

당신은 따옴표 또는 아포스트로피 여러 줄 문자열과 문자열에 대한 매우주의해야합니다. <form> 문자열에 자바 스크립트 구문 오류가 있습니다.

나는 당신을 위해 그것을 청소했고 (나의 선호 된 스타일로 구문을 바꾸었다) ...

StackOverflow의 구문 강조 표시가 문자열을 모두 빨간색으로 유지하는 방법에 유의하십시오. 대부분의 프로그래밍 편집자들도 그런 단서를 줄 것입니다.

$(TargetNode).after 
(
    '<form method="POST" action="http://dl.tccd.edu/index.php/classforums/posts/event=saveReply"> \ 
    <input type="hidden" name="subject" size="45" id="txt_subject" maxlength="200" value="">  \ 
    <br> Message:<br>                    \ 
    <textarea rows="20" style="width:70%;" name="message" id="message"></textarea>     \ 
    <br> <br>                      \ 
    <input type="submit" id="submit_post" value="Post Reply">          \ 
    <input type="hidden" name="post_id" value="1010815">           \ 
    <input type="hidden" name="thread_id" value="1010815">           \ 
    </form>                       \ 
    ' 
); 

.

추가 문제는이 질문을 따르기가 너무 어려워지지 않도록 새 질문을 만드십시오.

+0

http://stackoverflow.com/questions/3125674/add-a-dynamic-form-to-specific-pages-using-greasemonkey-and-jquery 새 질문을 열었습니다. 고맙습니다. 제쳐두고, 자바 스크립트에 사용할 편집기는 무엇입니까? – Parseltongue

+0

저는 주로 TextPad (http://www.textpad.com/products/textpad/index.html)와 SlickEdit (http://www.slickedit.com/)을 사용합니다. 하지만 메모장 ++ (http://notepad-plus-plus.org/)가 좋으며 무료입니다. –

관련 문제