YouTube回放Chrome扩展程序 [英] Youtube Playback Chrome Extension

查看:76
本文介绍了YouTube回放Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么它不能正常工作.

I cannot understand why this isn't working.

我已经检查了Google扩展名 dev文档,检查了一些示例代码.

I have checked the google extension dev docs, checked some sample code.

检查了其他stackoverflow问题/答案,而没有来自测试的任何正面反馈/结果.

Checked other stackoverflow Question/Answers without any positive feedback/results from testing.

此扩展程序非常简单

This extension is very simple

  1. 它显示弹出窗口,其中包含输入文本字段和按钮
  2. 单击它会通过 postMessage 将消息发送到内容脚本,以更新 document.getElementsByTagName("video")[0] .playbackRate
  3. 这将调整youtube或其他受支持的(未来冒险)视频 播放速度超出或低于默认值0.25、0.50、1、1.25、1.50、2或精确到1.4390之类的值
  4. 比使用所述控制台+ devtools等更容易,更快.这可以加快初始设置的速度...
  1. It displays a popup with an input text field and a button
  2. on clicking it will send a message to the content script via postMessage to update the document.getElementsByTagName("video")[0].playbackRate
  3. this will adjust youtubes or other supported (future venture) Video Playback Speed beyond or lower than the default of 0.25, 0.50, 1, 1.25, 1.50, 2 or to an exact value like 1.4390
  4. Easier and faster than using said console + devtools, etc..which speeds up the initial setup...

请帮助:)

manifest.json

{
  "manifest_version": 2,
  "name": "Youtube Playback",
  "version": "1.0",
  "description": "Manage Playback Speed With Any Value",
  "homepage_url": "https://github.com/DeanVanGreunen",
  "permissions": [
    "tabs",
    "activeTab"
  ],
  "browser_action": {
    "icon": "icon.png",
    "default_icon": "icon.png",
    "title": "Youtube Playback",
    "default_title": "Youtube Playback",
    "popup": "popup.html",
    "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"]
    }
  ]
}

popup.html

<script>
function setPlaybackSpeed(speed){
    chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
        var activeTab = tabs[0];
        chrome.tabs.sendMessage(activeTab.id, {action: "setPlaybackSpeed", "speed": speed});
    });
}
</script>
<div>
    <input id="text_playbackspeed" type="text" style="" placeholder="1" value="1"/>
    <button id="btn_updateplaybackspeed" style="">Update</button>
</div>

content.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if( request.action === "setPlaybackSpeed" ) {
            document.getElementsByTagName("video")[0].playbackRate = request.playback_speed;
        }
        return true;
    }
);

推荐答案

这是有效的解决方案(虽然有一段时间,但是您可以在这里忘了更新此线程)

Here is the working solution (its being a while however here you go, I forgot to update this thread)

此扩展程序非常简单

  • 它显示带有输入文本字段和按钮的弹出窗口
  • 点击它会向内容脚本发送一条消息
  • 通过postMessage更新文档.getElementsByTagName(视频")[0] .playbackRate
  • 这将调整youtube或其他受支持的(未来冒险)视频播放
  • 使用4来超出或低于默认速度0.25、0.50、1、1.25、1.50、2或最高4倍的原始速度
  • 精确值,例如1.4390
  • 比使用所述控制台+ devtools等更容易,更快.这可以加快初始设置的速度...

项目回购托管在Github上:

或通过以下方式获取最新版本:

或在下面查看最新的文件:

manifest.json

{
  "manifest_version": 2,
  "name": "Youtube Playback",
  "version": "1.0",
  "description": "Manage Playback Speed With Any Value",
  "homepage_url": "https://keybase.io/DeanVanGreunen",
  "repo_url": "https://github.com/DeanVanGreunen/YT_SpeedMeUpExtension",
  "permissions": [  
    "tabs",
    "activeTab"
  ],
  "icons": {
    "128": "icon.png"
  },
  "browser_action": {
    "default_icon": {
      "128": "icon.png"
    },

    "default_title": "Youtube Playback",
    "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"]
    }
  ]
}


popup.html

<style>
    #text_playbackspeed {
        padding: 2px;
        margin-bottom: 4px;
    }
    #leButtons, #findsMe {
        padding: 4px 8px;
        text-align: center;
        margin:0px auto;
    }
    #findsMe img{
        display: block;
        margin: 0 auto;
        width: 69px;
        height: 69px;
    }
</style>
<div>
    <input id="text_playbackspeed" type="text" style="" placeholder="1" value="1"/>
    <div id="leButtons">
        <button id="btn_updateplaybackspeed_minus" style="">-1</button>
        <button id="btn_updateplaybackspeed" style="">Update</button>
        <button id="btn_updateplaybackspeed_add" style="">+1</button>
    </div>
</div>
<div id="findsMe">
    <img src="https://avatars0.githubusercontent.com/u/22296075" alt="The Developer" />
    <a target="_blank" href="https://keybase.io/DeanVanGreunen">Find me</a>
</div>
<script type="text/javascript" src="popup.js"></script>


popup.js

function setPlaybackSpeed(speed){
    chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
        var activeTab = tabs[0];
        chrome.tabs.sendMessage(activeTab.id, {action: "setPlaybackSpeed", "speed": speed});
    });
}

function getPlaybackSpeed(){
    chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
        var activeTab = tabs[0];
        chrome.tabs.sendMessage(activeTab.id, {action: "getPlaybackSpeed"});
    });
}

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(sender.tab){
            if( request.action == "returnPlaybackSpeed" ) {
                document.getElementById('text_playbackspeed').value = request.speed;
            }
        }
    }
);

document.getElementById('btn_updateplaybackspeed_minus').addEventListener('click', function(event) {
    var num = parseFloat(document.getElementById('text_playbackspeed').value)-1;
    document.getElementById('text_playbackspeed').value = num;
});

document.getElementById('btn_updateplaybackspeed_add').addEventListener('click', function(event) {
    var num = parseFloat(document.getElementById('text_playbackspeed').value)+1;
    document.getElementById('text_playbackspeed').value = num;
});

document.getElementById('btn_updateplaybackspeed').addEventListener('click', function(event) {
    setPlaybackSpeed(document.getElementById('text_playbackspeed').value);
});


getPlaybackSpeed();


content.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(!sender.tab){
            if( request.action == "getPlaybackSpeed" ) {
                chrome.runtime.sendMessage({action: "returnPlaybackSpeed", speed: document.getElementsByTagName("video")[0].playbackRate}, function(){});
            } else if( request.action == "setPlaybackSpeed" ) {
                document.getElementsByTagName("video")[0].playbackRate = request.speed;
            }
        }
    }
);


icon.png

这篇关于YouTube回放Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆