2013-05-02 2 views
1

직접 링크 적용되지 않습니다 https://github.com/MosheBerman/MinimalOverflow/blob/master/styleswitcher.user.js크롬 userscript 스크립트 원격 CSS 스타일 시트를

내가 https://stackapps.com/questions/2143/minimaloverflow-a-themescript-for-stack-exchange에서 스크립트를 다운로드하여 드래그 앤 * .user.js가 크롬에서 내 확장 탭에 파일을 떨어졌다. 스크립트가 실행되고 alert을 사용하여 확인했습니다. 심지어 스크립트에서 alerthref 속성을 편집하여 올바르게 변경했는지 확인합니다. no styling applied http://i39.tinypic.com/23lo321.png

는 본질적으로 코드가 link 태그 외모와 href 속성을 변경합니다 스크립트가 CSS를 변경할 때마다

그러나, 적용된 스타일은 없다.

라인 (64)

function switchToStylesheet(sheet){ 

    for(var i=0; i<linkElements.length; i++){ 
     if(linkElements[i].getAttribute("rel") == "stylesheet"){ 

      //apply the new stylesheet 
      linkElements[i].href = sheet; 

      alert(linksElements[i].href); 
// shows https://github.com/MosheBerman/MinimalOverflow/raw/master/clean.css as expected 

      //We only want to replace the first stylesheet, so return. 
      //If SO decides to change any styles, just put it in a 
      //second stylesheet and link tag. The script should safely ignore it. 
      return; 
     } 
    } 
} 

내가 Version 25.0.1364.152 이 내가 Windows 7 64-bit

가 가

이 사람이이 Chrome, Javascript, 또는 Userscript 문제가 있는지 확인 할 수 실행하는거야?

+0

이 당신이 원하는 것이 아니라 다른 방법으로 당신은 시도 할 수 있습니다 : 세련된 https://chrome.google.com/webstore/detail/stylish/fjnbnpbmkenffdnngjfgmeleoegfcffe를 (플러그인은 _ 다른 브라우저에서도 사용할 수 있습니다 _). stackoverfllow 스타일 검색 (http://userstyles.org/styles/browse/stackoverflow)은 비슷한 스타일을 찾지 못했지만 웹 사이트의 요소를 검사하여 자신의 CSS로 덮어 쓰는 것이 매우 쉽습니다. 세련된 ... – Joonas

답변

1

"Referencing a .css file in github repo as stylesheet in a .html file"을 참조하십시오. Git은 잘못된 mime 형식의 CSS 파일 (.../raw/master/clean.css)을 제공합니다. Chrome 및 Firefox와 같은 브라우저는 (일반적으로) 그러한 CSS를 처리/적용하지 않습니다.

빠른 해결 방법은 CSS 파일을 사용자의 서버 또는 무료 파일 호스팅 사이트 중 하나에 호스팅하는 것입니다. 그런 다음에 설정 스크립트를 변경합니다

var pathToNewStylesheet = "http://YOUR_SERVER.COM/YOUR_PATH/clean.css"; 
+0

고마워요. 얼마나 많은 농구를 뛰어야하는지 믿을 수 없습니다. 더 이상 '접근성'과 같은 것이 없습니다. –

관련 문제