Custom media url

Open media in html in ONE click!

  1. // ==UserScript==
  2. // @name Custom media url
  3. // @namespace https://github.com/xue-blood/cup
  4. // @version 0.31
  5. // @description Open media in html in ONE click!
  6. // @author doolb
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your code here...
  16. var all = document.querySelectorAll('a');
  17. for(var i=0;i<all.length;i++){
  18. if( all[i].text.indexOf("mp4") != -1 ||
  19. all[i].text.indexOf("mkv") != -1 ||
  20. all[i].text.indexOf("wmv") != -1){
  21.  
  22. addurl('[M]','mpv',all[i]);
  23. addurl('[P]','potplayermini64',all[i]);
  24. addbtn('[C]',all[i]);
  25. }
  26. }
  27.  
  28. function addurl(title,prefix,element){
  29. var a = document.createElement('a');
  30. a.text = title;
  31. a.href = prefix + ':' + element.href;
  32. a.title='Open in '+prefix;
  33. element.parentElement.insertBefore(a,element);
  34. }
  35.  
  36. function addbtn(title,element){
  37. var b = document.createElement('input');
  38. b.value=title;
  39. b.setAttribute('data',element.href);
  40. b.type='button';
  41. b.title='Copy url to copyboard';
  42. b.style='display:inline';
  43. b.onclick=function(){
  44. copyToClipboard(b.getAttribute('data'));
  45. }
  46. element.parentElement.insertBefore(b,element);
  47. }
  48.  
  49. // by https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
  50. function copyToClipboard(text) {
  51. // Create a "hidden" input
  52. var aux = document.createElement("input");
  53. // Assign it the value of the specified element
  54. aux.setAttribute("value", text);
  55. // Append it to the body
  56. document.body.appendChild(aux);
  57. // Highlight its content
  58. aux.select();
  59. // Copy the highlighted text
  60. document.execCommand("copy");
  61. // Remove it from the body
  62. document.body.removeChild(aux);
  63. }
  64.  
  65.  
  66.  
  67. })();