var oldicons = document .querySelectorAll( 'link[rel="icon"], link[rel="shortcut icon"]' ); for ( var i = 0; i < oldicons.length; i++ ) { oldicons[i].setAttribute( "src" , "/newicon.png" ); }
var oldicons = document .querySelectorAll( 'link[rel="icon"], link[rel="shortcut icon"]' ); for ( var i = 0; i < oldicons.length; i++ ) { oldicons[i].setAttribute( "src" , "/newicon.png" ); }
var oldicons = document .querySelectorAll( 'link[rel="icon"], link[rel="shortcut icon"]' ); for ( var i = 0; i < oldicons.length; i++ ) { oldicons[i].setAttribute( "src" , "/newicon.png" ); }
var oldicons = document .querySelectorAll( 'link[rel="icon"], link[rel="shortcut icon"]' ); for ( var i = 0; i < oldicons.length; i++ ) { oldicons[i].setAttribute( "src" , "/newicon.png" ); }
- $ ( 'link [rel = "shortcut icon"]' ) .attr ( "src" , "/newicon.png" );
- $ ( 'link [rel $ = icon]' ) .remove ();
- $ ( 'head' ) .append ($ ( '<link rel = "shortcut icon" type = "image / x-icon" />' ) .attr ( 'href' , "/newicon.png" ));
- var c = document .createElement ( 'canvas' );
- c.height = c.width = 16;
- var x = c.getContext ( '2d' );
- x.font = '18px bold Calibri' ;
- x.fillStyle = '# 000' ;
- if (m) {
- x.fillText (parseInt (m [1])> 9? '9+' : m [1], 0, 16, 16);
- }
(15) - v.pupkin@gmail.com - GMail
- Object.prototype .__ defineSetter __ ( 'Id' , function (data) {
- alert ( "hooked data =" + data);
- });
- document .__ defineSetter __ ( 'title' , function (v) {
- delete document .title; // remove the old "handler"
- document .title = v; // intercept new data and put into variable
- document .__ defineSetter __ ( 'title' , arguments.callee); // and quickly return the handler to the place
- var m = / \ (([0-9] +) \) /. exec (v); // we take a regular bite with the number of messages with a variable
- var c = document .createElement ( 'canvas' ); // start the canvas. Create a canvas
- c.height = c.width = 16; // and assign it dimensions
- var x = c.getContext ( '2d' ); // get context
- x.font = '18px bold Calibri' ; // set the font style
- x.fillStyle = '# 000' ; // and fill color
- if (m) {
- x.fillText (parseInt (m [1])> 9? '9+' : m [1], 0, 16, 16); // If qty> 9, then show “9+”
- }
- var o = document .querySelectorAll ( 'link [rel = "icon"], link [rel = "shortcut icon"]' ); // find all possible favicon tags
- for ( var i = 0; i <o.length; i ++) {
- o [i] .parentNode.removeChild (o [i]); // and bang them,
- }
- var n = document .createElement ( 'link' ); // then re-create
- n.setAttribute ( 'rel' , 'icon' ); // with the required atrubutsy
- n.setAttribute ( 'href' , c.toDataURL ()); // c.toDataURL () gets the finished image on our canvas as text "data: image / png; base64, ......" /
- document .querySelector ( 'head' ) .appendChild (n); // well, and finally, apply the newly created favicon to the document. Voila!
- });
* This source code was highlighted with Source Code Highlighter .
- var c = document .createElement ( "canvas" ); // Use the same canvas
- c.height = c.width = 16;
- var cx = c.getContext ( "2d" );
- cx.beginPath (); // draw a blue square and black text on it
- cx.rect (0, 3, 18, 11); // and put them on canvas
- cx.fillStyle = "# 6DA3BD" ;
- cx.fill ();
- cx.font = "10px Normal Tahoma" ;
- cx.fillStyle = "#fff" ;
- var mark = document .querySelectorAll ( ".mark span" ); // get tsiferki from the page
- cx.fillText (parseInt (mark [0] .innerHTML), 0, 12, 16);
- // use favicon
- var oldicons = document .querySelectorAll ( 'link [rel = "icon"], link [rel = "shortcut icon"]' );
- for ( var i = 0; i <oldicons.length; i ++) {
- oldicons [i] .parentNode.removeChild (oldicons [i]);
- }
- var newicon = document .createElement ( "link" );
- newicon.setAttribute ( "rel" , "icon" );
- newicon.setAttribute ( "href" , c.toDataURL ());
- document .querySelector ( "head" ) .appendChild (newicon);
- // update the page every 2 minutes
- window.setTimeout ( function () {
- window.clearTimeout ();
- window.location.reload ();
- }, 120000);
Source: https://habr.com/ru/post/112551/
All Articles