'IP 변경'에 해당되는 글 1

  1. 2013.09.08 [Greasemonkey] 링크 주소 바꾸기

[Greasemonkey] 링크 주소 바꾸기

- 파일 확장자는 user.js

- 모든 링크를 찾아서 주소를 변경한다.
	var links = document.getElementsByTagName("a");
	for(var i = 0 ; i < links.length ; i++){
		ahref = links[i].href;
		if(ahref.indexOf("http://1.2.4.130:8088") == 0){
			links[i].href = ahref.replace("http://1.2.4.130", "http://211.8.3.20");
		}
	}

- Gmail에서는 잘 안되는거 같아 실행을 지연시킨다.
window.setTimeout(function(){
	//
}, 1000*3);

- 실행이 되긴 하지만 Gmail은 매번 페이지를 읽지 않으므로 다른 메일을 읽으면 동작하지 않는다.

- click 이벤트에 연결한다.
document.addEventListener('click', function(event) {
	ahref = "" + event.target;	
	if(ahref.indexOf("http://1.2.4.130:8088") == 0){
		window.location.href = "http://naver.com";
		event.stopPropagation();
		event.preventDefault();
	}
}, true);

- 현재 페이지가 이동하므로, 링크의 주소를 직접 고친다.
// ==UserScript==
// @name				Forwarding Trac IP
// @namespace		http://pantarei.tistory.com
// @description		Forwarding 130 to 20
// @include				https://mail.google.com/*
// @include				https://www.google.com/calendar/*
// @include				http://211.8.3.219/*
// ==/UserScript==

document.addEventListener('click', function(event) {
	if(event.target.tagName == "A"){
		ahref = "" + event.target;	
		if(ahref.indexOf("1.2.4.130") > 0){		
			event.target.setAttribute("href", ahref.replace("1.2.4.130", "211.8.3.20"));
		}
	}
}, true);
Trac 티켓 메일도 있지만 구글 캘린더에서도 Trac 링크가 있으므로 "http://"를 뺀다.
지메일에서 ":"와 같은 문자를 인코딩한다.
실제 발생한 click 이벤트가 처리되도록 막지 않는다.

- 지메일에서 구글 캘린더 알림 메일 링크
http://1.2.4.130:8088/projects/HelloTOW/attachment/wiki/WikiStart/fiddler.PNG //실제 링크
https://www.google.com/url?q=http%3A%2F%2F1.2.4.130%3A8088%2Fprojects%2FHelloTOW%2Fattachment%2Fwiki%2FWikiStart%2Ffiddler.PNG&usd=2&usg=AFQjCNH7xeM7IdMWgpYZBmGXde7gBgmWEg

- 2013-09-09
a 태그에서 실행되도록 추가


=-=>mouseover에 넣으면 더 좋을거 같다.