讨论 » 创建请求

Could Someone Help Me With Simple Script

§
发表于:2014-12-02
编辑于:2014-12-02

Could Someone Help Me With Simple Script

Hello Greasy Fork community, I don't know about userscripts much, so i aren't sure if this is possible.

Could someone help me with very simple script? I want to change favicon on Doit.im website. It includes task count - which makes me little bit anxious.

Favicon can be anything, but preferably same icon without task count.

Thank you very, very much. :)

woxxom管理员
§
发表于:2014-12-02
编辑于:2014-12-02

I'm not sure this can be done using a userscript, because the favicon is updated via canvas drawing in the externally loaded libs.js. But this is certainly possible with Fiddler (might be easy) or a custom Firefox addon that implements nsIHttpChannel interface (definitely not easy) by tampering the js code on-the-fly.

§
发表于:2014-12-03
编辑于:2014-12-03

Thanks for answer! I will do research on Fiddler. One question - if I change favicon with it, will it be permanent or will it revert back when i refresh site?

EDIT: I found this script to change google's favicon. if it's not too hard for you could you help me making it work for Doit.im? Thanks. Script below:

// ==UserScript==
// @name BetterFavicon
// @namespace planetargon
// @description A better favicon for google
// @include http://*.google.com/
// ==/UserScript==
 
var favicon_link_html = document.createElement('link');
favicon_link_html.rel = 'icon';
favicon_link_html.href = 'http://robbyonrails.com/files/google-favicon.ico';
favicon_link_html.type = 'image/x-icon';
 
try {
document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
}
catch(e) { }
woxxom管理员
§
发表于:2014-12-03

The problem is that doit.im changes the favicon dynamically. With Fiddler you can remove that part of code. As for your userscript sample, if you don't mind an occasional flicker of the favicon it might be possible to add a timer to periodically restore the favicon.

§
发表于:2014-12-03

I don't mind flicker at all just get rid of damn counter :D also if this is possible, it would be even better to restore favicon only when i refresh the Doit.im. They don't add counter if i don't visit today list. I just use contexts and don't visit today list at all. But if i refresh site, they still add counter. By the way, thanks for help. :)

woxxom管理员
§
发表于:2014-12-03
编辑于:2014-12-03

Doesn't flicker here.

// ==UserScript==
// @name    doit.im replace favicon
// @include https://i.doit.im/*
// @include http://i.doit.im/*
// @run-at  document-start
// @grant   none
// ==/UserScript==

window.addEventListener('DOMContentLoaded', function(e) {
  var icon = document.head.appendChild(document.createElement('link'));
  icon.href = '/favicon.ico';
  icon.rel = 'icon';

  new MutationObserver(function(mutations){
    for (var i=0, ml=mutations.length, m; (i<ml) && (m=mutations[i]); i++)
      for (var j=0, nodes=m.addedNodes, nl=nodes.length, n; (j<nl) && (n=nodes[j]); j++)
        if ((n.localName == 'link') && (n.rel == 'icon'))
          n.href = '/favicon.ico';
  }).observe(document.head, {subtree:true, childList:true});
});
§
发表于:2014-12-03
编辑于:2014-12-03

Thanks. But it does nothing. Do I need to change something to work? Sorry if stupid question. Thanks for script again :)

woxxom管理员
§
发表于:2014-12-03
编辑于:2014-12-03

Basically you need to install it and reopen/reload the page https://i.doit.im

§
发表于:2014-12-03

Thanks very much. :D I changed https to httpc and now it works. Doit.im doesn't run on https for some reason...

woxxom管理员
§
发表于:2014-12-03
编辑于:2014-12-04

Ah, okay. I've added both protocols to the code above just in case.

发表回复

登录以发表回复。