Custom media url

Open media in html in ONE click!

目前為 2018-05-27 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Custom media url
// @namespace    https://github.com/xue-blood/cup
// @version      0.31
// @description  Open media in html in ONE click!
// @author       doolb
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
var all = document.querySelectorAll('a');
for(var i=0;i<all.length;i++){
	if( all[i].text.indexOf("mp4") != -1 ||
		all[i].text.indexOf("mkv") != -1 ||
		all[i].text.indexOf("wmv") != -1){

		addurl('[M]','mpv',all[i]);
		addurl('[P]','potplayermini64',all[i]);
		addbtn('[C]',all[i]);
	}
}

function addurl(title,prefix,element){
	var a = document.createElement('a');
	a.text = title;
	a.href = prefix + ':' + element.href;
	a.title='Open in '+prefix;
	element.parentElement.insertBefore(a,element);
}

function addbtn(title,element){
	var b = document.createElement('input');
	b.value=title;
	b.setAttribute('data',element.href);
	b.type='button';
	b.title='Copy url to copyboard';
	b.style='display:inline';
	b.onclick=function(){
		copyToClipboard(b.getAttribute('data'));
	}
	element.parentElement.insertBefore(b,element);
}

// 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
function copyToClipboard(text) {
  // Create a "hidden" input
  var aux = document.createElement("input");
  // Assign it the value of the specified element
  aux.setAttribute("value", text);
  // Append it to the body
  document.body.appendChild(aux);
  // Highlight its content
  aux.select();
  // Copy the highlighted text
  document.execCommand("copy");
  // Remove it from the body
  document.body.removeChild(aux);
}



})();