2011-08-19 12 views
1

잘못 설계된 페이지의 CSS 요소를 변경하는 스크립트를 작성했습니다. 내가 크롬을 시험해 보았을 때, 이제는 완벽하게 작동합니다. 나는 웹에 배치 한 지금 북마크 텍스트로 이것을 사용하고 있습니다 :북마크가 Firefox에서 작동하지 않습니다.

javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://myexamplewebsite.com/files/adjustPage.js';})(); 

그것은 크롬에 완벽하게 작동하지만 최신 파이어 폭스 나 IE에서 작동하지 않습니다. 크롬과 파이어 폭스의 오류 콘솔을 살펴본 결과 어떤 문제도 불평하지 않습니다. Firefox는 오류 콘솔의 'code'필드에 코드를 입력하고 평가할 때도 반응하지 않습니다.

Firefox는 하단의 작은 상태 표시 줄에서 "Read myexamplewebsite.com"이라고 말합니다.하지만 그 밖의 것은 없습니다.

같은 서버에 'hello world'스크립트를 배치했기 때문에 위에서 실행중인 북마크릿 코드의 버킷이 아닙니다. 정상적으로 작동했습니다.

내 스크립트에 대해 Firefox/IE에서 마음에 들지 않는 것을 해결하는 더 좋은 방법이 있습니까?

관심이 있으시면 지금 실행중인 코드를 참조하십시오. ; 게코에서 지원되지 않습니다

var section = document.getElementsByClassName('cqGroupBox'); 
for(var i in section) { 
var children = section[i].childNodes; 

for(var j in children){ 
    if(children[j].innerText == 'Detected on configuration') { 
     var style = section[i].getAttribute('style'); 
     style += ' display:none;'; 
     section[i].setAttribute('style', style); 
     break; 
    } 
} 
} 

var tables = document.getElementsByTagName('table'); 
for(var i in tables) { 
try{ 
    var styleNode = tables[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(style.match('top: 434px; left: 120px;') 
    || style.match('top: 461px; left: 120px;') 
    || style.match('top: 434px; left: 456px;') 
    || style.match('top: 461px; left: 456px;')){ 
     style += ' display:none;'; 
     tables[i].attributes.getNamedItem('style').firstChild.nodeValue = style; 
    } 
} catch(err){continue;} 
} 


var labels = document.getElementsByTagName('label'); 
for(var i in labels) { 
try{ 
    var styleNode = labels[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(labels[i].innerText == 'OS' 
    || labels[i].innerText == 'App. Server' 
    || labels[i].innerText == 'DBMS' 
    || labels[i].innerText == 'Web Server'){ 
     style += ' display:none;'; 
     labels[i].attributes.getNamedItem('style').firstChild.nodeValue = style; 
    } 
} catch(err){continue;} 
} 

var divs = document.getElementsByTagName('div'); 
for(var i in divs) { 
try { 
    var styleNode = divs[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(style.match('top: 291px; left: 23px;')){ 
     style.replace('height: 109px;',''); 
     divs[i].attributes.getNamedItem('style').firstChild.nodeValue = style; 

     innerDivs = divs[i].getElementsByTagName('div'); 
     for(var j in innerDivs){ 
      try { 
       innerStyle = innerDivs[j].attributes.getNamedItem('style').firstChild.nodeValue; 
       if(innerStyle.match('width: 665px; height: 109px;')){ 
        innerStyle = innerStyle.replace('height: 109px;',''); 
        innerStyle += ' font-size: 130%'; 
        innerDivs[j].attributes.getNamedItem('style').firstChild.nodeValue = innerStyle; 
       } 
      } catch(err){continue;} 
     } 
    } 
} catch(err){continue;} 
} 
+1

이 좋은 것 등, 게코 DOM을 볼 수 있지만, 어쩌면 수표와 일치하지 않습니다 html plage가 제공하는 것 :)이 스크립트가 실행되어야하는 페이지가 필요합니다. – walialu

+0

좋은 지적입니다. 페이지의 크기가 모두 절대적이며 하드 코딩 된 것으로 가정합니다 (페이지가 좋지 않음). 독점 시스템 (ClearQuest 버그 추적 시스템)이기 때문에 나는 페이지를 공유 할 수 없지만 내가 찾을 수있는 것에 대한 제안이 있습니까? – HXCaine

답변

3

innerText는 (그것을위한 표준을 만드는 노력이 지금은 거기까지) 비표준 속성입니다 : 코드의 추함을 용서하십시오, 그것은 매우 신속하고 더러운 해킹했다 . textContent을 대신 사용하면 문제가 해결됩니까?

+0

이것은 확실히 올바른 방향으로 나를 이끌었습니다. 이 변경 작업을 수행 할 때 FF에서 4 개 루프 중 첫 번째 루프가 작동했는데 이는 Chrome 관련 코드를 사용하고 있음을 나타내는 좋은 징후입니다. 내 스크립트를 수정하기 위해 다른 점이 무엇인지 계속 살펴볼 것입니다. 이것을 쉽게 볼 수있는 방법을 알고 있습니까? – HXCaine

+0

@HXCaine 좋은 시작은 Firefox의 예외 콘솔을보고 어떤 예외가 던져지고 있는지 확인하는 것입니다. 물론 스크립트가 모든 예외를 자동으로 포착하는 경우에는 도움이되지 않습니다. 또 다른 옵션은 스크립트에 경고를 두어 도달하지 않은 첫 번째 줄이 무엇인지 파악한 다음 그 바로 앞에 오는 것을 볼 수 있는지 확인하는 것입니다. –

+0

이 스크립트의 주된 문제는 필드에 값을 할당한다는 것입니다. 예를 들어'tables [i] .attributes.getNamedItem ('style'). firstChild.nodeValue = style'는'nodeValue'의 값을 변경하지 않습니다. 이것이 원래의 질문이 아니라는 것을 알고 있지만 같은 문제에 대해 새로운 질문을하고 싶지는 않습니다. Firefox에서 할당이 작동하지 않는 이유를 알고 있습니까? – HXCaine

0

다음은 Chrome, Firefox 3.6 및 최신 Firefox (2011 년 8 월)에서 작동하는 고정 코드입니다. 어쩌면이 계산 된 스타일이 아닌)

var section = document.getElementsByClassName('cqGroupBox'); 
for(var i in section) { 
var children = section[i].childNodes; 

for(var j in children){ 
    if(children[j].textContent == 'Detected on configuration') { 
     var style = section[i].getAttribute('style'); 
     style += ' display:none;'; 
     section[i].setAttribute('style', style); 
     break; 
    } 
} 
} 

var tables = document.getElementsByTagName('table'); 
for(var i in tables) { 
try{ 
    var styleNode = tables[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(style.match('top: 434px; left: 120px;') 
    || style.match('top: 461px; left: 120px;') 
    || style.match('top: 434px; left: 456px;') 
    || style.match('top: 461px; left: 456px;')){ 
     style += ' display:none;'; 
     styleNode.firstChild.nodeValue = style; 
     tables[i].setAttribute('style', style); 
    } 
} catch(err){continue;} 
} 


var labels = document.getElementsByTagName('label'); 
for(var i in labels) { 
try{ 
    var styleNode = labels[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(labels[i].textContent == 'OS' 
    || labels[i].textContent == 'App. Server' 
    || labels[i].textContent == 'DBMS' 
    || labels[i].textContent == 'Web Server'){ 
     style += ' display:none;'; 
     styleNode.firstChild.nodeValue = style; 
     labels[i].setAttribute('style', style); 
    } 
} catch(err){continue;} 
} 

var divs = document.getElementsByTagName('div'); 
for(var i in divs) { 
try { 
    var styleNode = divs[i].attributes.getNamedItem('style'); 
    var style = styleNode.firstChild.nodeValue; 

    if(style == null) { 
     continue; 
    } 

    if(style.match('top: 291px; left: 23px;')){ 
     style = style.replace('height: 109px;',''); 
     styleNode.firstChild.nodeValue = style; 
     divs[i].setAttribute('style', style); 

     innerDivs = divs[i].getElementsByTagName('div'); 
     for(var j in innerDivs){ 
      try { 
       innerStyleNode = innerDivs[j].attributes.getNamedItem('style'); 
            innerStyle = innerStyleNode.firstChild.nodeValue; 

            if(innerStyle == null) { 
          continue; 
          } 

            if(innerStyle.match('width: 665px;') 
             && innerStyle.match(' height: 109px;')){ 
        innerStyle = innerStyle.replace('height: 109px;',''); 
        innerStyle += ' font-size: 130%'; 
        innerDivs[j].setAttribute('style', innerStyle); 
       } 
      } catch(err){continue;} 
     } 
    } 
} catch(err){continue;} 
} 

당신이 사용할 수있는 무엇을 알아내는 문제가있는 경우

관련 문제