Created
August 12, 2017 06:45
-
-
Save mingl0280/4506b6b8eab5c5feec46a90241b20276 to your computer and use it in GitHub Desktop.
Greasemonkey script adding download button to bilibili paint board. You can find the download button at the description area. Please load the pictures first.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name bilibili place download | |
// @namespace BPD | |
// @include http://live.bilibili.com/pages/1702/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var timeoutSeconds = 10; | |
function bpd() { | |
var canvases = document.getElementsByTagName('canvas'); | |
var activityBlock = document.getElementsByClassName('activity-introduction') [0]; | |
var downloadDiv; | |
if (document.getElementById('downImageLayer') === null) { | |
downloadDiv = document.createElement('div'); | |
downloadDiv.id = 'downImageLayer'; | |
activityBlock.appendChild(downloadDiv); | |
document.timingPBlock = document.createElement('p'); | |
document.timingSpanBlock = document.createElement('span'); | |
document.timingSpanBlock.id = 'downloadUpdateClocker'; | |
document.timingSpanBlock.textContent = timeoutSeconds; | |
document.timingPBlock.textContent = 'Seconds till next update: '; | |
document.timingPBlock.appendChild(document.timingSpanBlock); | |
downloadDiv.appendChild(document.timingPBlock); | |
} else { | |
clearInterval(document.timingSpanClocker); | |
downloadDiv = document.getElementById('downImageLayer'); | |
$(downloadDiv).empty(); | |
downloadDiv.appendChild(document.timingPBlock); | |
} | |
for (var i = 0; i < canvases.length; i++) | |
{ | |
var canvasDataStr = canvases[i].toDataURL(); | |
var newLink = document.createElement('a'); | |
var brline = document.createElement('br'); | |
canvasDataStr = canvasDataStr.replace('image/png', 'image/png;headers=Content-Disposition: attachment; filename=' + i.toString() + '.png'); | |
newLink.style.color = 'white'; | |
newLink.textContent = 'Download #' + (i + 1).toString(); | |
newLink.href = canvasDataStr; | |
newLink.target = '_blank'; | |
if (i != 0) | |
downloadDiv.appendChild(brline); | |
downloadDiv.appendChild(newLink); | |
} | |
document.iUpdateDownloadNotice = timeoutSeconds; | |
document.timingSpanBlock.textContent = document.iUpdateDownloadNotice; | |
document.timingSpanClocker = setInterval(updateNotice, 1000); | |
document.iFlushTimeout = setTimeout(bpd, timeoutSeconds*1000); | |
} | |
function updateNotice() { | |
document.iUpdateDownloadNotice--; | |
document.timingSpanBlock.textContent = document.iUpdateDownloadNotice; | |
} | |
bpd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment