WebRTC media source switcher

Forcefully chose a specific webrtc input/output audio/video device

当前为 2020-04-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WebRTC media source switcher
  3. // @namespace https://daniil.it
  4. // @version 0.1.2
  5. // @description Forcefully chose a specific webrtc input/output audio/video device
  6. // @author Daniil Gentili <daniil@daniil.it>
  7. // @match https://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var hidden = {
  14. enumerateDevices: navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices)
  15. }
  16. navigator.mediaDevices.enumerateDevices = () => hidden.enumerateDevices().then(res => {
  17. if (window.newRes) {
  18. return window.newRes;
  19. } else {
  20. window.newRes = [];
  21. }
  22.  
  23. var temp = {};
  24. var tempLabels = {};
  25. for (var i = 0; i < res.length; i++) {
  26. if (!temp[res[i].kind]) {
  27. temp[res[i].kind] = [];
  28. tempLabels[res[i].kind] = "Choose a "+res[i].kind+" device:\n";
  29. }
  30. temp[res[i].kind].push(res[i])
  31. tempLabels[res[i].kind] += temp[res[i].kind].length+": "+res[i].label+"\n"
  32. }
  33. for (let [key, value] of Object.entries(tempLabels)) {
  34. var choice = prompt(value);
  35. window.newRes.push(temp[key][choice-1]);
  36. }
  37.  
  38. return window.newRes;
  39. })
  40. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址