-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSaveImageWithCtrlClick.user.js
48 lines (43 loc) · 1.38 KB
/
SaveImageWithCtrlClick.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name Image Saving with Ctrl+Click/Shift [GLOBAL]
// @namespace imageSaving
// @description Ctrl+Click/Shift image saving for most single-image pages
// @author NightLancerX
// @match *://*/*.jpg*
// @match *://*/*.png*
// @version 2.1
// @homepageURL https://github.com/NightLancer/PixivPreview
// @downloadURL https://github.com/NightLancer/PixivPreview/raw/master/SaveImageWithCtrlClick.user.js
// @license MIT License
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
let img = document.querySelectorAll('img')[0];
let imgSrc = img.src;
function main()
{
let anchor = document.createElement('a');
anchor.href = img.src;
anchor.target = '_self';
anchor.download = (imgSrc.indexOf('?')>-1)? imgSrc.substring(imgSrc.lastIndexOf("/")+1, imgSrc.indexOf('?')): imgSrc.substring(imgSrc.lastIndexOf("/")+1);
document.body.appendChild(anchor);
anchor.click();
};
img.onclick = function(e)
{
if (e.ctrlKey) //save with Ctrl+Click
{
e.preventDefault();
main();
};
};
document.onkeyup = function(e)
{
if (e.keyCode == 16) //save with shift
{
main();
}
};
})();