Skip to content

Instantly share code, notes, and snippets.

@agran
Last active May 6, 2025 11:46
Show Gist options
  • Save agran/51e0a7bd5f5ffaed3760d390d850de24 to your computer and use it in GitHub Desktop.
Save agran/51e0a7bd5f5ffaed3760d390d850de24 to your computer and use it in GitHub Desktop.
Скрипт для tampermonkey, который решают проблему с копированием формул с сайта sdamgia.ru в MS Word
// ==UserScript==
// @name sdamgia img
// @namespace http://tampermonkey.net/
// @version 2025-05-06
// @description try to take over the world!
// @author agran
// @match *.sdamgia.ru/*
// @grant none
// ==/UserScript==
function getCanvasFromImage(image) {
var scale = 5;
if(image.src.includes('.png') || image.src.includes('&png=')){
scale = 1;
}
const canvas = document.createElement('canvas');
canvas.width = image.naturalWidth*scale;
canvas.height = image.naturalHeight*scale;
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
return canvas;
}
(function() {
'use strict';
$('img').attr('src',function(i,e){
return e.replace(/\/.+\.sdamgia\.ru/,"//"+document.domain);
})
$( "img" ).one("load",function(){
var img = $(this)[0];
console.log(img.src);
console.log(getCanvasFromImage(img).toDataURL());
img.setAttribute('width', img.width);
img.setAttribute('height', img.height);
img.src = getCanvasFromImage(img).toDataURL();
if($(this).css('float') == 'right'){
$(this).after('<p>');
$(this).css('float', '');
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment