Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.69 KB | None | 0 0
  1. private void on_click(WebKit.DOM.EventTarget target, WebKit.DOM.Event event)
  2.     {
  3.         try
  4.         {
  5.             //var image = (WebKit.DOM.HTMLImageElement)target;
  6.             //image.set_attribute("class", "clickable-img-hover");
  7.         }
  8.         catch(GLib.Error e)
  9.         {
  10.  
  11.         }
  12.     }
  13.  
  14. public static void webkit_web_extension_initialize (WebKit.WebExtension web_extension)
  15. {
  16.     string PROG = "[webkit2_webextension_minimal_so.so] ";    
  17.    
  18.     print(PROG + "PLUGIN activated\n");
  19.  
  20.     web_extension.page_created.connect((extension, web_page)=> {
  21.         print(PROG + "SIGNAL: page_created\n");
  22.    
  23.    
  24.    
  25.    
  26.      
  27.       try {
  28.        
  29.    
  30.        
  31. var dom = web_page.get_dom_document();
  32.  
  33. WebKit.DOM.Element img = dom.create_element("img");
  34. img.set_attribute("src", "file:///home/o/avatar.png");
  35. img.set_attribute("alt", "avatar-1.jpg");
  36. ((WebKit.DOM.EventTarget) img).add_event_listener_with_closure("click", on_click, false);
  37. dom.body.insert_before(img, null);
  38.  
  39.  
  40. } catch (FileError e) {
  41.  
  42.     stdout.printf ("Message: \"%s\"\n", e.message);
  43.         stdout.printf ("Error code: FileError.EXIST = %d\n", e.code);
  44.         stdout.printf ("FileErrors identification: %" + uint32.FORMAT + "\n", e.domain);
  45.  
  46.     }
  47.    
  48.        
  49.         web_page.send_request.connect((request)=>
  50.         {
  51.            
  52.        
  53.             if(request.uri.has_prefix("http://www.google") || request.uri.has_prefix("data")){
  54.                 print(PROG + "SIGNAL: send request [REJECTED] " + request.uri + "\n");
  55.                 return true;  // true => block query
  56.             }
  57.             print(PROG + "SIGNAL: send request " + request.uri + "\n");
  58.             return false;
  59.         });
  60.        
  61.         return;
  62.     });
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement