2013-05-20 5 views
-1

웹 사이트에 새로운 기능을 추가하는 userscript를 만듭니다. 웹 사이트에 많은 사용자가 있지만 사용자를 검색 할 수있는 기능이 없습니다.
그런 함수를 만들고 싶습니다. 그렇게하기 위해 이미 다른 검색 목적으로 기존 검색 페이지에 버튼을 만들었습니다. 버튼을 클릭하면 Google에서 입력을 검색하고 URL을 가져와 존재하지 않는 페이지의 HTML 코드로 결과를 표시하는 스크립트가 필요합니다.

사용자 스크립트로 URL을 가짜로 만들면 HTML을 표시 할 수 있습니까?

그렇지 않은 경우 페이지 내의 특정 HTML을 바꿀 수 있습니까?

코드가 그다지 재미 있지 않습니다. 링크가있는 단추를 추가하고 존재하지 않는 페이지에있을 때 선택합니다.
Tampermonkey - 존재하지 않는 URL을 사용하여 페이지 추가

CODE : 내 자신의 질문에 대답하기위한

if (document.URL == "http://www.bierdopje.com/search" || document.URL == "http://www.bierdopje.com/search/" || window.location.href.indexOf("search/shows") > -1 || window.location.href.indexOf("search/episodes") > -1 || window.location.href.indexOf("search/forum") > -1) { 
var users = document.createElement('li'); 
users.setAttribute('class', 'strong'); 
var UsersNode = document.createTextNode("Gebruikers"); 
var UsersLink = document.createElement('a'); 
UsersLink.setAttribute('href', 'http://www.bierdopje.com/search/users/'); 

document.getElementById("submenu").childNodes[1].appendChild(users).appendChild(UsersLink).appendChild(UsersNode); 

if (window.location.href.indexOf("search/users/") > -1) { 
    UsersLink.setAttribute('href', './'); 
    UsersLink.setAttribute('class', 'selected'); 
} 
} 

+0

이 질문은 현재 명확하지 않으며 "너무 지역화되어 있습니다". [이 체크리스트] (http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist)를 작성하십시오. [SSCCE] (http://sscce.org/)를 만들고 실제 HTML 대 원하는 HTML을 게시하십시오. –

+0

아마도 맞을 것입니다. 다행히도 나는 내 자신의 문제를 해결했다. 어쨌든 질문을 읽어 주셔서 감사합니다. – Tom

답변

0

미안하지만 브록 아담스처럼 이미 말했다 : 너무 지역화되었을 수 있습니다.
URL을 위조하는 해결책은 404 찾을 수없는 콘텐츠를 대체하는 것입니다. 헤더와 단락과 용기처럼이 있다면

는 변수를 만들어 컨테이너를 찾은 다음 다른 변수로 교체 :

// find the container 
var example = document.getElementById('container').childNodes[0]; 

// set new container 
var newcontainer = document.createElement('div'); 
newcontainer.setAttribute('id', 'ncontainer'); 

// replace the existing container with the new one 
example.parentNode.replaceChild(replacement, example); 

// write content to the new container 
document.getElementById('ncontainer').innerHTML ='<p>This is not a 404 anymore</p>'; 

아마 훨씬 더 짧은 있습니다 방법은 Google에서 (자바 스크립트 대체) 찾을 수 있습니다.

document.title = "WEBSITE TITLE"; 
0

당신은 더 나은 귀하의 브라우저 확장을 만들어야합니다

에서는 사용자가 다음과 같은 제목을 설정할 수 있습니다

document.write() 


페이지를 마치려면 사용, 전체 페이지를 교체하려면 . 모양이 복잡하지 않습니다.

이렇게하면 확장 기능에서 튀어 나오는 HTML 창에서 Javascript 기능을 실행할 수 있습니다.
참조 https://justinribeiro.github.io/chrome-extensions-codelab-gdg-oakdale/images/screenshot-20150108-step-02-blank-popup-loaded.png