Netfix QueueSorter (chrome) - 帮助修改脚本以按字母顺序对组进行排序

发布于 2024-10-09 08:02:27 字数 3265 浏览 0 评论 0原文

我安装了 Netflix 队列排序器 作为扩展。但是,它会随机为某个类型内的电影分配顺序。我希望它按类型中的名称排序。

我打开 C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\Extensions\ExtensionId\1.13_0\script.js ,我可以看到 javascript 仍然需要一些工作。这是我修改后的方法,按标题和流派排序。

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;
    };

I have the Netflix Queue sorter installed as an extension. However, it randomly assigns an order to the movies within a genre. I want it to sort by name within the genre.

I open C:\Users\MyUserName\AppData\Local\Google\Chrome\User Data\Default\Extensions\ExtensionId\1.13_0\script.js and I can see that the javascript still needs some work. Here is the my modified method which sorts on title and genre.

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);
}

My problem is that while it sorts fine, it's not ignoring the articles. Is my sort function off? I think it can be defined more succinctly (in one line).

    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;
    };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2024-10-16 08:02:27

我想通了。该代码的构建是为了将articles 数组设置为空。这是一个小WTF,但我用几行注释修复了它。

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

对于任何使用此扩展的人,我通过将 jquery 库添加到扩展来修复它。我在manifest.json 中添加了对它的引用。

然后只需用此方法替换现有的 sortByGenre

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);
}

即可进入 chrome 中的开发人员模式,将其加载解压或将其打包为 crx,导航到 chrome 中的文件,然后安装扩展。

I figured it out. The code was built to set the articles array to empty. It's a small WTF, but I fixed it with a few commented lines.

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

for anyone who uses this extension, I fixed it by adding the jquery library to the extension. I added a reference to it in manifest.json.

Then just replace the existing sortByGenre with this method

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);
}

once you do that you can go into developer mode in chrome and either load it unpacked or pack it as a crx, navigate to the file within chrome, and install the extension.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文