Skip to content

Commit

Permalink
added userscript which uses coubdl-bridge's url scheme (you need to r…
Browse files Browse the repository at this point in the history
…un `CoubDownload-Bridge.exe -register`, to unregister `CoubDownload-Bridge.exe -register false`
  • Loading branch information
Venipa committed Jul 3, 2019
1 parent 5f0974e commit d94891a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CoubDownload-Bridge-Userscript/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 6
}
77 changes: 77 additions & 0 deletions CoubDownload-Bridge-Userscript/coub-bridge.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ==UserScript==
// @name Coub-Bridge
// @namespace https://venipa.net
// @version 0.1
// @description try to take over the world!
// @author Venipa
// @match https://*.coub.com/*
// @match https://coub.com/*
// @grant none
// ==/UserScript==

(function() {
// 'use strict';
const downloadButton = function() {
const btn = document.createElement('a');
btn.innerText = "Download Coub";
btn.style.padding = "8px 12px";
btn.style.color = "#fff";
btn.style.background = "#000";
btn.style.lineHeight = 1;
btn.style.fontSize = "0.875rem";
btn.style.alignSelf = 'center';
btn.style.borderRadius = '4px';
btn.style.marginRight = '8px';
return btn;
}
var log = {
debug: function(msg, ...params) {
console.log('[coub-bridge|debug] ', msg, params);
},
tag: function(tag, msg, ...params) {
console.log('[coub-bridge|' + tag + '] ', msg, params);
}
};
log.debug('boot');
const buttonId = 'coubdl-download';
var checkCoubs = function() {
var coubs = document.querySelectorAll('.coubs-list .coub[coub-block]:not(.timeline-banner), .coub-page > .coub-block-col .coub[coub-block]');
var coubRelated = document.querySelectorAll('.suggests-block-col .suggest__list > .suggest__item');
log.debug(coubs, coubRelated);

coubs.forEach(function(x) {
var controls = x.querySelector('.description__controls');
if (controls.querySelectorAll('#' + buttonId).length === 0) {
var coubId = x.getAttribute('data-permalink');
var downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = "coubdl-bridge://" + coubId;
controls.prepend(downloadBtn);
}
});
coubRelated.forEach(function(x) {
if (x.querySelectorAll('#' + buttonId).length === 0) {
var coubId = x.getAttribute('data-permalink');
var downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = "coubdl-bridge://" + coubId;
downloadBtn.style.padding = '4px 6px';
downloadBtn.style.position = 'absolute';
downloadBtn.style.top = 0;
downloadBtn.style.right = 0;
downloadBtn.style.marginTop = '8px';
downloadBtn.style.marginRight = '8px';
downloadBtn.style.zIndex = 9999;
x.prepend(downloadBtn);
}
});
};
var worker;
var workerFunc = function() {
clearInterval(worker);
checkCoubs();
worker = setInterval(workerFunc, 2500);
};
workerFunc();
log.debug(worker);
})();
8 changes: 8 additions & 0 deletions CoubDownload-Bridge-Userscript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "coubdownload-bridge-sserscript",
"version": "1.0.0",
"main": "coub-bridge.user.js",
"repository": "https://github.com/Venipa/coubdl-bridge",
"author": "Venipa",
"license": "MIT"
}
2 changes: 1 addition & 1 deletion CoubDownload-Bridge/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool Exists()
}
public void Save()
{
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this));
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, Formatting.Indented));
}
}
}

0 comments on commit d94891a

Please sign in to comment.