linterna-magica-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linterna-magica-commit] [277] Fixes support #108050.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [277] Fixes support #108050.
Date: Sun, 27 May 2012 15:12:55 +0000

Revision: 277
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=277
Author:   valkov
Date:     2012-05-27 15:12:55 +0000 (Sun, 27 May 2012)
Log Message:
-----------
Fixes support #108050. Full detail of changes in the bug report.

Ticket Links:
------------
    http://savannah.gnu.org/support/?108050

Modified Paths:
--------------
    trunk/src/lm_extract_js_swfobject.js
    trunk/src/lm_site_facebook.js

Modified: trunk/src/lm_extract_js_swfobject.js
===================================================================
--- trunk/src/lm_extract_js_swfobject.js        2012-05-14 17:19:02 UTC (rev 
276)
+++ trunk/src/lm_extract_js_swfobject.js        2012-05-27 15:12:55 UTC (rev 
277)
@@ -45,50 +45,97 @@
            "(\\\s*,\\\s*([^,\\\)]+)){0,1}"+
            "(\\\s*,\\\s*([^,\\\)]+)){0,1}"+
            "\\\)",
-       "im");
+       "img");
 
     var data = this.script_data;
-    var constructor = data.match(constructor_re);
-    var height, width, el;
-    var object_data= new Object() ;
+    var constructor = null;
+    var var_name = null;
+    var id_re = null;
+    var el = null;
+    var count = 0;
+    var last_constructor = null;
 
-    if (!constructor)
+    while (constructor = constructor_re.exec(data))
     {
-       return null;
-    }
+       last_constructor = constructor;
+       el = constructor[4].replace(/\'|\"/g, "");
 
-    el = constructor[4].replace(/\'|\"/g, "");
+       if (!document.getElementById(el))
+       {
+           // variable_name = constructor[2]
+           var_name = 
+               constructor[2].replace(/window\[\"/,"").
+               replace(/\"\]/,"");
 
-    if (!document.getElementById(el))
-    {
-       // variable_name = constructor[2]
-       var var_name = 
-           constructor[2].replace(/window\[\"/,"").
-           replace(/\"\]/,"");
+           id_re = new RegExp(
+               var_name+"\\."+
+                   "write\\("+"("+"\\'"+'|\\"'+")*"+
+                   "([A-Za-z0-9_-]+)"+"("+"\\'"+'|\\"'+")*"+
+                   "\\)",
+               "ig");
+           
+           el = null;
+           var inner_count = 0;
 
-       var id_re = new RegExp(
-           var_name+"\\."+
-               "write\\("+"("+"\\'"+'|\\"'+")*"+
-               "([A-Za-z0-9_-]+)"+"("+"\\'"+'|\\"'+")*"+
-               "\\)",
-           "i");
+           while (el = id_re.exec(data))
+           {
+               // If there are more than two SWFObject object in the
+               // same <script> tag, we need the id of the DOM
+               // element where the current matched SWF object will
+               // write the SWF object. Theoretically the first match
+               // of a SWFObject constructor should be related to the
+               // first match for the SWFObject write method, the
+               // second construcor to the second write method and so
+               // on. This way we should be able to match the exact
+               // id.
+               //
+               // See bug #108050:
+               // https://savannah.nongnu.org/support/?108050
+               if (inner_count >= count)
+                   
+               {
+                   break;
+               }
+               
+               inner_count++;
+           }
 
-       el = data.match(id_re);
+           // Do not know where the object should be
+           if (!el)
+           {
+               this.log("LinternaMagica.extract_object_from_script_"+
+                        "swfobject:\n"+
+                        "No id extracted from SWFObject.write method "+
+                        "id_re" +id_re,4);
 
-       // Do not know where the object should be
-       if (!el)
-       {
-           this.log("LinternaMagica.extract_object_from_script_"+
-                    "swfobject:\n"+
-                    "No id extracted from SWFObject.write method "+data+
-                    "id_re" +id_re,4);
+               continue;
+           }
 
-           return null;
+           el = el[el.length-2];
+           
+           // We have an element that will hold LM, break.
+           //
+           // See bug #108050:
+           // https://savannah.nongnu.org/support/?108050
+           if (document.getElementById(el))
+           {
+               break;
+           }
        }
+       count++;
+    }
 
-       el = el[el.length-2];
+    constructor = last_constructor;
+
+    // All attempts to find where to place LM failed. Exit.
+    if (!document.getElementById(el))
+    {
+       return null;
     }
 
+    var height, width;
+    var object_data= new Object();
+
     if (this.skip_object_if_id(el))
     {
        return null;

Modified: trunk/src/lm_site_facebook.js
===================================================================
--- trunk/src/lm_site_facebook.js       2012-05-14 17:19:02 UTC (rev 276)
+++ trunk/src/lm_site_facebook.js       2012-05-27 15:12:55 UTC (rev 277)
@@ -92,6 +92,19 @@
     var result = new Object();
 
     // Found DOM object
+    // Might not work anymore. Can't test it.
+    // 
+    // While fixing bug #108050, even when Gnash was installed the
+    // browser didn't render it where the clip should be. Manually
+    // setting higher flash version in Gnash settings did not help
+    // either.
+    //
+    // Also the fix for bug #108050 introduced the
+    // flash_plugin_installed(), so clips are always extracted from
+    // script tags. This fragment should probably be removed.
+    //
+    // See bug #108050:
+    // https://savannah.nongnu.org/support/?108050
     if (!this.script_data)
     {
        result.link_re = new RegExp (
@@ -104,11 +117,9 @@
     else
     {
        result.link_re = new RegExp (
-           "addVariable\\\((\\\"|\\\')video_src(\\\"|\\\'),\\\s*"+
-               "(\\\"|\\\')([^\\\"\\\']+)(\\\"|\\\')(\\\))\\\;{1}",
+           
"(\\\"|\\\')video_src(\\\"|\\\'),\\\s*(\\\"|\\\')([^\\\"\\\']+)(\\\"|\\\'){1}",
            "i");
-
-       result.link_position = 3;
+       result.link_position = 2;
     }
 
     return result;
@@ -127,25 +138,109 @@
 
 // Reference. Just returns false
 LinternaMagica.prototype.sites["facebook.com"].
-    do_not_clean_amps_in_extracted_link = "video.google.com";
+do_not_clean_amps_in_extracted_link = "video.google.com";
 
 // See bug #108013:
 // https://savannah.nongnu.org/support/index.php?108013
 LinternaMagica.prototype.sites["facebook.com"].
 skip_script_processing = function()
 {
-    if (/video\.php/i.test(window.location.href) &&
-       this.script_data.length >= 15360 )
+    if (/(video|photo)\.php/i.test(window.location.href) &&
+       this.script_data.length >= 26214400 )
     {
-       // Skip scripts larger than 15 KB on video pages.
+       // Skip scripts larger than 25 KB on video pages.
        return false;
     }
-    else if (!/video\.php/i.test(window.location.href) &&
-            this.script_data.length >= 5120)
+    else if (!/(video|photo)\.php/i.test(window.location.href) &&
+            this.script_data.length >= 5120)
     {
-       // Skip scripts larger than 5 KB on non-video pages.
-       return false;
+       // Skip scripts larger than 5 KB on non-video pages.
+       return false;
     }
 
     return true;
 }
+
+LinternaMagica.prototype.sites["facebook.com"].
+extract_hd_links_from_script_if_link =
+function()
+{
+    var data = this.script_data;
+
+    var hd_strings = ["lowqual_src", "highqual_src" ];
+    var hd_links = new Array();
+    var l,i;
+
+    for(i=0, l=hd_strings.length; i<=l; i++)
+    {
+       var hd_string = hd_strings[i];
+       var link_re = new RegExp (
+           "(\\\"|\\\')"+hd_string+"(\\\"|\\\'),\\\s*(\\\"|\\\')"+
+               "([^\\\"\\\']+)(\\\"|\\\'){1}",
+           "i");
+
+       var match = data.match(link_re);
+
+       if (match && match[match.length-2])
+       {
+           var link = new Object();
+           // The # at the end of hte link is needed, because
+           // Facebook adds some event listenerers for click events
+           // for anchor elements that break the default browser
+           // behaviour. This causes the HD links to load directly in
+           // the browser. This work-around works because ... ? I
+           // suppose they filter links with #.
+           link.url = 
+               this.sites["facebook.com"].
+               process_extracted_link(match[match.length-2])+"#";
+
+
+           link.label = (hd_string == "lowqual_src") ?
+               this._("Low quality") : this._("Hight quality");
+
+           hd_links.push(link);
+       } else {
+           break;
+       }
+    }
+
+    if (hd_links.length > 0)
+    {
+       return hd_links;
+    }
+
+    return null;
+}
+
+LinternaMagica.prototype.sites["facebook.com"].css_fixes =
+function(object_data)
+{
+    // Facebook adds some event listenerers for click events for the
+    // naviation (next/prev video/photo) anchor elements that break
+    // the default browser behaviour. It is suspected that the page is
+    // requested at the background and injected in the DOM. Linterna
+    // Magica does not load for next or previous clips. The
+    // work-around is to force the browser to load the link as if it
+    // was no Facebook JavaScript - on the foreground.
+
+    var next = document.querySelector(".photoPageNextNav");
+    var prev = document.querySelector(".photoPagePrevNav");
+
+    var fb_nav_click_fn = function(ev)
+    {
+       window.location = this.getAttribute("href");
+    }
+
+    if (next)
+    {
+       next.addEventListener("click", fb_nav_click_fn, false);
+    }
+
+    if (prev)
+    {
+       prev.addEventListener("click", fb_nav_click_fn, false);
+    }
+}
+ 
+// Reference. Calls the logic that processes <script> tags
+LinternaMagica.prototype.sites["facebook.com"].flash_plugin_installed = 
"youtube.com";




reply via email to

[Prev in Thread] Current Thread [Next in Thread]