2010-12-29 3 views
0

Netflix Queue sorter이 확장 프로그램으로 설치되어 있습니다. 그러나 장르 내의 영화에 임의로 순서를 지정합니다. 장르 내에서 이름순으로 정렬하고 싶습니다.Netfix QueueSorter (chrome) - 그룹을 알파벳순으로 정렬하는 스크립트 수정 도움말

C : \ Users \ MyUserName \ AppData \ Local \ Google \ Chrome \ User Data \ Default \ Extensions \ ExtensionId \ 1.13_0 \ script.js를 열고 자바 스크립트가 여전히 약간의 작업이 필요하다는 것을 알 수 있습니다. 여기 제목과 장르에 따라 분류 된 수정 된 방법이 있습니다.

function sortByTitleAndGenre() { 
    var articles; 
    sortInfo = []; 
    var pos = 1; 

    var articlesKey = 'sortByTitle.articles'; 
    var ignoreArticlesKey = 'sortByTitle.ignoreArticles'; 
    var ignoreArticles = GM_getValue(ignoreArticlesKey); 
    if (undefined === ignoreArticles) { 
     // Use true as default as Netflix ignores articles too. 
     ignoreArticles = true; 

     // Store keys so that users can change it via about:config. 
     GM_setValue(ignoreArticlesKey, ignoreArticles); 
     // The articles are used "as-is", so there must be a space after 
     // each one in most cases. To avoid typos in the default, use []. 
     articles = [ 
      "A ", 
      "AN ", 
      "THE ", 
      "EL ", 
      "LA ", 
      "LE ", 
      "LES ", 
      "IL ", 
      "L'" 
     ]; 
     GM_setValue(articlesKey, articles.join(',').toUpperCase()); 
    } 

    var elts = customGetElementsByClassName(document, 'input', 'o'); 
    for (var idx = 0; idx < elts.length; idx++) { 
     var boxName = elts[idx].name; 
     var boxId = boxName.substring(2); 
     // If a movie is both at home and in the queue, or a movie has been 
     // watched but is still in the queue, there is both _0 and _1. 
     // Here we either one works. 
     var titleId = 'b0' + boxId + '_0'; 
     var titleElt = document.getElementById(titleId); 

     var genre = $("tr[data-mid='" + boxId + "'] .gn .genre").text().toUpperCase(); 

     var title = titleElt.innerHTML.toUpperCase(); 
     if (ignoreArticles) { 
      // Get the articles, but default to empty string. 
      var articlesStr = GM_getValue(articlesKey, '') || ''; 
      articlesStr = articlesStr.toUpperCase(); 
      articles = articlesStr.split(','); 
      for (var aa = 0; aa < articles.length; aa++) { 
       var article = articles[aa].toUpperCase(); 
       if (0 === title.indexOf(article)) { 
        // Move article to the end of the string. 
        title = title.substring(article.length) + 
          ', ' + article; 
        break; 
       } 
      } 
     } 

     var record = { 
      "id": boxId, 
      "title": title, 
      "genre": genre, 
      "origPos": pos++ 
     }; 
     sortInfo.push(record); 
    } 

    var sortFn = function (a, b) { 
     if (a.genre == b.genre) 
      return a.title > b.title ? -1 : 1; 
     else 
      return a.genre > b.genre ? -1 : 1; 
    }; 
    sortInfo.sort(sortFn); 

    setOrder("origPos", elts); 
} 

내 문제는 정렬하는 동안 기사를 무시하지 않는다는 것입니다. 내 정렬 기능이 꺼져 있습니까? 나는 그것이 더 간결하게 (한 줄로) 정의 될 수 있다고 생각한다.

var sortFn = function (a, b) { 
     if (a.genre == b.genre) 
      return a.title > b.title ? -1 : 1; 
     else 
      return a.genre > b.genre ? -1 : 1; 
    }; 

답변

0

알아 냈습니다. 이 코드는 articles 배열을 비어 있도록 설정되었습니다. 작은 WTF이지만 몇 줄의 주석을 달아 수정했습니다.

//var articlesStr = GM_getValue(articlesKey, '') || ''; 
//articlesStr = articlesStr.toUpperCase(); 
//articles = articlesStr.split(','); 

이 확장 프로그램을 사용하는 모든 사용자를 위해 jquery 라이브러리를 확장 프로그램에 추가하여 수정했습니다. manifest.json에이 참조를 추가했습니다. 당신은 크롬에서 개발자 모드로 가서 하나 크롬에서 파일을 탐색, 그것은 압축을 풀로드하거나 CRX로 포장 할 수 그렇게되면

그럼 그냥이 방법

function sortByGenre() { 
    var articles; 
    sortInfo = []; 
    var pos = 1; 

    var articlesKey = 'sortByTitle.articles'; 
    var ignoreArticlesKey = 'sortByTitle.ignoreArticles'; 
    var ignoreArticles = GM_getValue(ignoreArticlesKey); 
    if (undefined === ignoreArticles) { 
     // Use true as default as Netflix ignores articles too. 
     ignoreArticles = true; 

     // Store keys so that users can change it via about:config. 
     GM_setValue(ignoreArticlesKey, ignoreArticles); 
     // The articles are used "as-is", so there must be a space after 
     // each one in most cases. To avoid typos in the default, use []. 
     articles = [ 
      "A ", 
      "AN ", 
      "THE ", 
      "EL ", 
      "LA ", 
      "LE ", 
      "LES ", 
      "IL ", 
      "L'" 
     ]; 
     //GM_setValue(articlesKey, articles.join(',').toUpperCase()); 
    } 

    var elts = customGetElementsByClassName(document, 'input', 'o'); 
    for (var idx = 0; idx < elts.length; idx++) { 
     var boxName = elts[idx].name; 
     var boxId = boxName.substring(2); 
     // If a movie is both at home and in the queue, or a movie has been 
     // watched but is still in the queue, there is both _0 and _1. 
     // Here we either one works. 
     var titleId = 'b0' + boxId + '_0'; 
     var titleElt = document.getElementById(titleId); 

     var genre = $("tr[data-mid='" + boxId + "'] .gn .genre").text().toUpperCase(); 

     var title = titleElt.innerHTML.toUpperCase(); 
     if (ignoreArticles) { 
      // Get the articles, but default to empty string. 
      //var articlesStr = GM_getValue(articlesKey, '') || ''; 
      //articlesStr = articlesStr.toUpperCase(); 
      //articles = articlesStr.split(','); 
      for (var aa = 0; aa < articles.length; aa++) { 
       var article = articles[aa].toUpperCase(); 
       if (0 === title.indexOf(article)) { 
        // Move article to the end of the string. 
        title = title.substring(article.length) + 
          ', ' + article; 
        break; 
       } 
      } 
     } 

     var record = { 
      "id": boxId, 
      "title": title, 
      "genre": genre, 
      "origPos": pos++ 
     }; 
     sortInfo.push(record); 
    } 

    var sortFn = function (a, b) { 
     if (a.genre == b.genre) 
      return a.title > b.title ? -1 : 1; 
     else 
      return a.genre > b.genre ? -1 : 1; 
    }; 
    sortInfo.sort(sortFn); 

    setOrder("origPos", elts); 
} 

으로 기존 sortByGenre 교체 , 확장을 설치하십시오.

관련 문제