Skip to content

Commit

Permalink
Use debug from npm instad of custom debug solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed May 14, 2017
1 parent 09e817c commit 06e58a6
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 479 deletions.
4 changes: 3 additions & 1 deletion aeks/aeks.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// @namespace https://github.com/Charcoal-SE/
// @description Automatically enable keyboard shortcuts for any SE site you're on. This may require a reload for the setting to take effect.
// @author Cerbrus
// @contributor J F
// @attribution Michiel Dommerholt (https://github.com/Cerbrus)
// @version 1.1.0
// @version 1.1.1
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/aeks/aeks.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/aeks/aeks.user.js
// @supportURL https://github.com/Charcoal-SE/Userscripts/issues
Expand All @@ -20,5 +21,6 @@
// @exclude *://chat.stackoverflow.com/*
// @exclude *://blog.stackoverflow.com/*
// @exclude *://*.area51.stackexchange.com/*
// @require https://wzrd.in/standalone/debug@%5E2.6.6
// @grant none
// ==/UserScript==
16 changes: 7 additions & 9 deletions aeks/aeks.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// @namespace https://github.com/Charcoal-SE/
// @description Automatically enable keyboard shortcuts for any SE site you're on. This may require a reload for the setting to take effect.
// @author Cerbrus
// @contributor J F
// @attribution Michiel Dommerholt (https://github.com/Cerbrus)
// @version 1.1.0
// @version 1.1.1
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/aeks/aeks.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/aeks/aeks.user.js
// @supportURL https://github.com/Charcoal-SE/Userscripts/issues
Expand All @@ -20,24 +21,21 @@
// @exclude *://chat.stackoverflow.com/*
// @exclude *://blog.stackoverflow.com/*
// @exclude *://*.area51.stackexchange.com/*
// @require https://wzrd.in/standalone/debug@%5E2.6.6
// @grant none
// ==/UserScript==

(function () {
"use strict";
const createDebug = window.debug;
const debug = createDebug("aeks");

var userscript = function ($) {
function log(message) {
if (console && console.log) {
console.log(message);
}
}

var userLink = $(".my-profile, .profile-me").attr("href");

// AEKS has already ran on this site, or the user doesn't have an account here.
if (!userLink || localStorage.aeksFinished) {
log("AEKS cancelled: User has no account or AEKS already finished on this site.");
debug("AEKS cancelled: User has no account or AEKS already finished on this site.");
return;
}

Expand All @@ -53,7 +51,7 @@
params,
function () {
localStorage.aeksFinished = true;
log("AEKS finished on this site.");
debug("AEKS finished on this site.");
}
);
};
Expand Down
3 changes: 2 additions & 1 deletion autoflagging/autoflagging.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// @contributor angussidney
// @contributor ArtOfCode
// @contributor Cerbrus
// @version 0.14.9
// @version 0.14.10
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.user.js
// @supportURL https://github.com/Charcoal-SE/Userscripts/issues
Expand All @@ -17,5 +17,6 @@
// @match *://chat.stackexchange.com/rooms/56223/the-spam-blot*
// @match *://chat.stackoverflow.com/rooms/111347/sobotics*
// @require https://cdn.rawgit.com/joewalnes/reconnecting-websocket/f8055b77ba75e5d564ffb50d20a483bdd7edccdf/reconnecting-websocket.min.js
// @require https://wzrd.in/standalone/debug@%5E2.6.6
// @grant none
// ==/UserScript==
65 changes: 24 additions & 41 deletions autoflagging/autoflagging.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// @contributor angussidney
// @contributor ArtOfCode
// @contributor Cerbrus
// @version 0.14.9
// @version 0.14.10
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.user.js
// @supportURL https://github.com/Charcoal-SE/Userscripts/issues
Expand All @@ -17,6 +17,7 @@
// @match *://chat.stackexchange.com/rooms/56223/the-spam-blot*
// @match *://chat.stackoverflow.com/rooms/111347/sobotics*
// @require https://cdn.rawgit.com/joewalnes/reconnecting-websocket/f8055b77ba75e5d564ffb50d20a483bdd7edccdf/reconnecting-websocket.min.js
// @require https://wzrd.in/standalone/debug@%5E2.6.6
// @grant none
// ==/UserScript==

Expand All @@ -27,7 +28,12 @@

(function () {
"use strict";
// console.log("Autoflagging Information started.");
const createDebug = window.debug;
const debug = createDebug("aim");
debug.decorate = createDebug("aim:decorate");
debug.ws = createDebug("aim:ws");
debug.queue = createDebug("aim:queue");
debug("started");

// Inject CSS
var css = window.document.createElement("link");
Expand All @@ -45,26 +51,6 @@
// Constants
var hOP = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
window.autoflagging = {};
autoflagging.traceKey = "autoflagging-trace";
autoflagging.trace = function (enable) {
// Enable/disable trace
if (enable) {
console.log("Autoflagging trace enabled.");
window.localStorage.setItem(autoflagging.traceKey, "true");
} else {
console.log("Autoflagging trace disabled.");
window.localStorage.removeItem(autoflagging.traceKey);
}
return enable;
};
autoflagging.log = function (object) {
// Trace enabled?
if (window.localStorage.getItem(autoflagging.traceKey) !== "true") {
return;
}
console.log("Time: " + new Date().toISOString().substring(11, 23));
console.log(object);
};
autoflagging.smokeyIds = { // this is Smokey's user ID for each supported domain
"chat.stackexchange.com": 120914,
"chat.stackoverflow.com": 3735529,
Expand All @@ -89,8 +75,7 @@
* `element` is a message (i.e. has the .message class)
*/
autoflagging.decorateMessage = function ($message, data) {
autoflagging.log("DECORATE " + JSON.stringify(data));
autoflagging.log($message);
debug.decorate(JSON.stringify(data), $message);

autoflagging.decorate($message.children(".ai-information"), data);
autoflagging.decorate($message.find(".meta .ai-information"), data);
Expand Down Expand Up @@ -130,7 +115,7 @@
}
})
.fail(function (xhr) {
autoflagging.log("Failed to load reasons: " + xhr.statusText);
debug("Failed to load reasons: " + xhr.statusText);
});
}
};
Expand Down Expand Up @@ -339,8 +324,7 @@
* message itself and to the 'meta'-element shown on hovering over the message.
*/
autoflagging.addSpinnerToMessage = function ($message) {
autoflagging.log("ADD SPINNER");
autoflagging.log($message);
debug("add spinner to", $message);
autoflagging.addSpinner($message);
autoflagging.addSpinner($message.find(".meta"), true);
};
Expand All @@ -366,13 +350,13 @@
* It will use the results to decorate the Smokey reports which are already on the page.
*/
autoflagging.callAPI = function (urls, page) {
autoflagging.log("Call API");
debug("Call API");
if (page == null) {
page = 1;
}
var autoflagData = {};
var url = autoflagging.baseURL + "&page=" + page + "&urls=" + urls;
autoflagging.log("URL: " + url);
debug("URL:", url);
$.get(url, function (data) {
// Group information by link
for (var i = 0; i < data.items.length; i++) {
Expand Down Expand Up @@ -468,13 +452,12 @@
autoflagging.socket.onmessage = function (message) {
function decorate(selector, data) {
(function _deco() {
autoflagging.log("Attempting to decorate \"" + selector + "\" with " + JSON.stringify(data));
autoflagging.log($(selector).parents(".message"));
debug.decorate("Attempting to decorate \"" + selector + "\" with", data, "message:", $(selector).parents(".message"));
if ($(selector).parents(".message").find(".ai-spinner, .ai-information.ai-loaded").length > 0) {
autoflagging.decorateMessage($(selector).parents(".message"), data);
} else {
// MS is faster than chat; add the decorate operation to the queue
autoflagging.log("Queueing " + selector);
debug.queue("Queueing", selector);
autoflagging.msgQueue.push(_deco);
}
})();
Expand All @@ -489,31 +472,31 @@
break;
default: {
// Analyze socket message
autoflagging.log(jsonData.message);
debug.ws("got message", jsonData.message);
var flagLog = jsonData.message.flag_log;
var deletionLog = jsonData.message.deletion_log;
var feedback = jsonData.message.feedback;
var notFlagged = jsonData.message.not_flagged;
if (typeof flagLog != "undefined") {
// Autoflagging information
autoflagging.log(flagLog.user_name + " autoflagged " + flagLog.post.link);
debug.ws(flagLog.user, "autoflagged", flagLog.post);
let selector = autoflagging.selector + "a[href^='" + flagLog.post.link + "']";
decorate(selector, flagLog.post);
} else if (typeof deletionLog != "undefined") {
// Deletion log
autoflagging.log(deletionLog.post_link + " deleted");
debug.ws("deleted:", deletionLog);
let selector = autoflagging.selector + "a[href^='" + deletionLog.post_link + "']";
$(selector).parents(".content").addClass("ai-deleted");
} else if (typeof feedback != "undefined") {
// Feedback
autoflagging.log(feedback.user_name + " posted " + feedback.symbol + " on " + feedback.post_link, feedback); // feedback_type
debug.ws(feedback.user, "posted", feedback.symbol, "on", feedback.post_link, feedback); // feedback_type
let selector = autoflagging.selector + "a[href^='" + feedback.post_link + "']";
decorate(selector, {
feedbacks: [feedback]
});
} else if (typeof notFlagged != "undefined") {
// Not flagged
autoflagging.log(notFlagged.post.link + " not flagged");
debug.ws(notFlagged.post, "not flagged");
let selector = autoflagging.selector + "a[href^='" + notFlagged.post.link + "']";
decorate(selector, notFlagged.post);
}
Expand All @@ -523,7 +506,7 @@
};

autoflagging.socket.onopen = function () {
autoflagging.log("WebSocket opened.");
debug.ws("WebSocket opened.");
// Send authentication
autoflagging.socket.send(JSON.stringify({
identifier: JSON.stringify({
Expand All @@ -534,7 +517,7 @@
}));
};
autoflagging.socket.onclose = function (close) {
autoflagging.log("WebSocket closed: " + close.code + " - " + close.reason + ".");
debug.ws("WebSocket closed:", close);
};

// Sometimes, autoflagging information arrives before the chat message.
Expand All @@ -554,8 +537,8 @@
var args = arguments;
q.forEach(function (f) {
setTimeout(function () {
autoflagging.log("Resolving queue: " + JSON.stringify(args));
autoflagging.log(f);
debug.queue("Resolving queue: " + JSON.stringify(args));
debug(f);
f.apply(self, args);
}, 100);
});
Expand Down
4 changes: 3 additions & 1 deletion fdsc/fdsc.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// @author ArtOfCode
// @contributor angussidney
// @contributor rene
// @contributor J F
// @attribution Brock Adams (https://github.com/BrockA)
// @version 1.14.0
// @version 1.14.1
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fdsc/fdsc.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fdsc/fdsc.user.js
// @supportURL https://github.com/Charcoal-SE/Userscripts/issues
Expand All @@ -23,5 +24,6 @@
// @exclude *://blog.stackoverflow.com/*
// @exclude *://*.area51.stackexchange.com/*
// @require https://cdn.rawgit.com/ofirdagan/cross-domain-local-storage/d779a81a6383475a1bf88595a98b10a8bd5bb4ae/dist/scripts/xdLocalStorage.min.js
// @require https://wzrd.in/standalone/debug@%5E2.6.6
// @grant none
// ==/UserScript==

0 comments on commit 06e58a6

Please sign in to comment.