switch to mobile version on facebook video page

When you open a video in facebook, you're redirected to mobile version so that it can play in HTML5 player

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://www.wtfpl.net/ for more details. */

// ==UserScript==
// @name switch to mobile version on facebook video page
// @namespace http://rboci.blogspot.com/
// @description When you open a video in facebook, you're redirected to mobile version so that it can play in HTML5 player
// @match https://www.facebook.com/*
// @run-at document-start
// @version 0.0.9
// @license WTFPL
// @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
// ==/UserScript==  

// match 4 types of URLs (relative and absolute):
//  https://www.facebook.com/mavikocaelicomtr/videos/836587179720780/
//  https://www.facebook.com/video.php?v=10152484650042694
//  /mavikocaelicomtr/videos/836587179720780/
//  /video.php?v=10152484650042694
var videoURLRe = /(?:www.facebook.com|^)\/(?:video\.php\?v=|[^\/]+\/videos\/).+/;

if (videoURLRe.test(content.document.location.href)) {
  var target = content.document.location.href.replace("www.facebook", "m.facebook");
  window.location.replace(target)
}

// install a hook that will redirect us if a link to video is clicked
// possible alternative approaches (so I do not forget):
//   http://stackoverflow.com/a/6390389/520567 - using timer to check current URL
//   http://stackoverflow.com/a/7381436/520567 - proxy the pushState() method
if (document.addEventListener ){
  document.addEventListener("click", function(event) {
    var targetElement = event.target || event.srcElement;
    // TODO: support deeper search for parent element with a href attribute
    var href = targetElement.getAttribute('href') || targetElement.parentElement.getAttribute('href') ;
    if (href && videoURLRe.test(href)) {
      var target = "";
      if (href.indexOf("/") == 0) {
        target = "https://m.facebook.com" + href
      } else {
        target = href.replace("www.facebook", "m.facebook");
      }
      window.location.assign(target);
    }   
  }, true);
}