diff --git a/README.md b/README.md index 009289e..84841dc 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Play: - Play modes for those who only caption or only draw - Enter pressed in caption mode submits the caption - Ability to bookmark games without participating -- Show your panel position and track changes in unfinished games list +- Show your panel position and track changes in unfinished games list and your experience Forum: @@ -89,6 +89,11 @@ Forum: ## CHANGELOG +1.75.2016.2 +- Fixed captions of created games not being registered for progress tracking +- Added tracking of changes in your level progress +- Added an option to set smoothing threshold + 1.74.2016.2 - New canvas: ability to apply custom CSS, experimental diff --git a/drawception-anbt.user.js b/drawception-anbt.user.js index a9b8c81..c494e44 100644 --- a/drawception-anbt.user.js +++ b/drawception-anbt.user.js @@ -2,7 +2,7 @@ // @name Drawception ANBT // @author Grom PE // @namespace http://grompe.org.ru/ -// @version 1.74.2016.2 +// @version 1.75.2016.2 // @description Enhancement script for Drawception.com - Artists Need Better Tools // @downloadURL https://raw.github.com/grompe/Drawception-ANBT/master/drawception-anbt.user.js // @match http://drawception.com/* @@ -14,8 +14,8 @@ function wrapped() { -var SCRIPT_VERSION = "1.74.2016.2"; -var NEWCANVAS_VERSION = 24; // Increase to update the cached canvas +var SCRIPT_VERSION = "1.75.2016.2"; +var NEWCANVAS_VERSION = 25; // Increase to update the cached canvas // == DEFAULT OPTIONS == @@ -98,7 +98,7 @@ Play - Play modes for those who only caption or only draw - Enter pressed in caption mode submits the caption - Ability to bookmark games without participating -- Show your panel position and track changes in unfinished games list +- Show your panel position and track changes in unfinished games list and your experience Forum - Better-looking timestamps with correct timezone - Clickable drawing panels @@ -981,7 +981,7 @@ function deeper_main() stupidPlugin.setAttribute("width", "1"); stupidPlugin.setAttribute("height", "1"); container.appendChild(stupidPlugin); - if (options.fixTabletPluginGoingAWOL) fixPluginGoingAWOL(); + if (options.fixTabletPluginGoingAWOL) fixPluginGoingAWOL(); } bindCanvasEvents(); if (window.insandbox) @@ -2093,6 +2093,11 @@ function betterCreateGame() } }); } + + if (options.rememberPosition && $(".page-header h1").text().match(/Game Created/)) + { + panelPositions.registerPanel(); + } } function betterView() @@ -2403,23 +2408,10 @@ function betterPanel() if (options.rememberPosition && $(".regForm > .lead").text().match(/public game/)) // your own panel { - panelPositions.load(); - if (!panelPositions.player[panelId]) + panelPositions.registerPanel(panelId, function(position) { - var profileUrl = $(".btn").has(".avatar").attr("href"); - $.get(profileUrl, function(html) - { - html = html.replace(/]*>/ig, ''); // prevent image preload - var profilePage = $.parseHTML(html); - var panelProgressText = $(profilePage).find("a[href='" + location.pathname + "']").next().find(".progress-bar-text").text(); - var panelPosition = parseInt(panelProgressText.match(/\d+/)[0]); - panelPositions.player[panelId] = panelPosition; - panelPositions.clear(profilePage); - panelPositions.save(); - - $(".regForm > .lead").append("
").append($("").text(panelProgressText)); - }); - } + $(".regForm > .lead").append("
").append($("").text(position.join(" of "))); + }); } } @@ -2427,21 +2419,27 @@ var panelPositions = { player: null, last: null, + level: null, + experience: null, load: function () { - function loadObj(key) + function loadObj(key, fallback) { var val = localStorage.getItem(key); - return val && JSON.parse(val) || {}; + return val && JSON.parse(val) || fallback; } - panelPositions.player = loadObj("gpe_panelPositions"); - panelPositions.last = loadObj("gpe_lastGamePositions"); + panelPositions.player = loadObj("gpe_panelPositions", {}); + panelPositions.last = loadObj("gpe_lastGamePositions", {}); + panelPositions.level = loadObj("gpe_lastLevel", null); + panelPositions.experience = loadObj("gpe_lastExperience", null); }, save: function () { localStorage.setItem("gpe_panelPositions", JSON.stringify(panelPositions.player)); localStorage.setItem("gpe_lastGamePositions", JSON.stringify(panelPositions.last)); + localStorage.setItem("gpe_lastLevel", JSON.stringify(panelPositions.level)); + localStorage.setItem("gpe_lastExperience", JSON.stringify(panelPositions.experience)); }, clear: function (page) { @@ -2456,6 +2454,42 @@ var panelPositions = }).get(); clearKeys(panelPositions.player, existingIds); clearKeys(panelPositions.last, existingIds); + }, + registerPanel: function (panelId, callback) + { + function getPanelPosition (link) + { + var panelProgressText = link.next().find(".progress-bar-text").text(); + return [parseInt(panelProgressText.match(/\d+/)[0]), parseInt(panelProgressText.match(/\d+/g)[1])]; + } + + panelPositions.load(); + // panelId is undefined when the game is just created + if (!panelId || !panelPositions.player[panelId]) + { + var profileUrl = $(".btn").has(".avatar").attr("href"); + $.get(profileUrl, function(html) + { + html = html.replace(/]*>/ig, ''); // prevent image preload + var profilePage = $.parseHTML(html); + + // Panel panelId is just created, record its position + if (panelId) + { + var position = getPanelPosition($(profilePage).find("a[href='" + location.pathname + "']")); + panelPositions.player[panelId] = position[0]; + callback && callback(position); + } + + // Panels with position 1 are always ours + $(profilePage).find("a") + .filter(function() { return $(this).next().hasClass("progress-striped") && getPanelPosition($(this))[0] == 1; }) + .each(function() { panelPositions.player[getPanelId(this.href)] = 1; }); + + panelPositions.clear(profilePage); + panelPositions.save(); + }); + } } }; @@ -2790,12 +2824,12 @@ function betterPlayer() var panelId = getPanelId($(this).prev().attr("href")); var playerPanelPosition = panelPositions.player[panelId]; var lastSeenPanelPosition = panelPositions.last[panelId]; - var panelProgress = $(this).find(".progress-bar-text"); - var panelProgressText = panelProgress.text(); + var panelProgressLabel = $(this).find(".progress-bar-text"); + var panelProgressText = panelProgressLabel.text(); var panelPosition = parseInt(panelProgressText.match(/\d+/)[0]); var totalPanelCount = parseInt(panelProgressText.match(/\d+/g)[1]); - panelProgress.css("pointer-events", "none"); // to make tooltips work under label + panelProgressLabel.css("pointer-events", "none"); // to make tooltips work under label if ((playerPanelPosition || lastSeenPanelPosition || panelPosition) < panelPosition) { $(this).find(".progress-bar") @@ -2805,21 +2839,21 @@ function betterPlayer() { $('
') .width((Math.min(lastSeenPanelPosition || panelPosition, panelPosition) - playerPanelPosition) / totalPanelCount * 100 + "%") - .insertBefore(panelProgress) + .insertBefore(panelProgressLabel) .tooltip(); } if (lastSeenPanelPosition && panelPosition > lastSeenPanelPosition) { $('
') .width((panelPosition - lastSeenPanelPosition) / totalPanelCount * 100 + "%") - .insertBefore(panelProgress) + .insertBefore(panelProgressLabel) .tooltip(); } if (lastSeenPanelPosition && panelPosition < lastSeenPanelPosition) { $('
') .width(1 / totalPanelCount * 100 + "%") - .insertBefore(panelProgress) + .insertBefore(panelProgressLabel) .tooltip(); } if (playerPanelPosition) @@ -2832,6 +2866,46 @@ function betterPlayer() panelPositions.last[panelId] = panelPosition; }); + + var levelProgress = $(".progress-bar-profile .progress-bar"); + var levelProgressLabel = $(".progress-bar-profile-text"); + var profileHeaderLabel = $(".profile-user-header p:last"); + var currentLevel = parseInt(profileHeaderLabel.text().match(/\d+/)[0]); + var currentExperience = parseInt(levelProgressLabel.text().match(/\d+/)[0]); + if (panelPositions.level && panelPositions.experience) + { + if (currentLevel != panelPositions.level) + { + levelProgress + .removeClass("progress-bar-info") + .addClass(currentLevel > panelPositions.level ? "progress-bar-success" : "progress-bar-danger"); + profileHeaderLabel.text(profileHeaderLabel.text().replace(/\d+/, + currentLevel + " (" + (currentLevel > panelPositions.level ? "+" : "") + (currentLevel - panelPositions.level) + ")")); + } + else + { + var experienceChange = currentExperience - panelPositions.experience; + if (experienceChange != 0) + { + var levelProgressBarWidth = parseFloat(levelProgress.attr("aria-valuenow")) / 100; + var experienceToLevelUp = parseInt(levelProgressLabel.text().match(/\d+/g)[1]); + var experiencePointWidth = (1 - levelProgressBarWidth) / experienceToLevelUp; + var experienceSinceLevelUp = Math.round(levelProgressBarWidth / experiencePointWidth); + var experienceAbsChange = Math.abs(experienceChange); + $(".progress-bar-profile .progress-bar") + .width((experienceSinceLevelUp - experienceAbsChange) * experiencePointWidth * 100 + "%"); + $('
') + .width(experienceAbsChange * experiencePointWidth * 100 + "%") + .addClass(experienceChange > 0 ? "progress-bar-success" : "progress-bar-danger") + .insertBefore(levelProgressLabel); + levelProgressLabel.text( + currentExperience + " XP (" + experienceToLevelUp + " to next level, " + + experienceAbsChange + " " + (experienceChange > 0 ? "gained" : "lost") + " recently)"); + } + } + } + panelPositions.level = currentLevel; + panelPositions.experience = currentExperience; panelPositions.save(); } @@ -2971,7 +3045,7 @@ function betterForum() day = parseInt(m[5], 10); year = parseInt(m[6], 10) + 2000; t.text("edited: " + convertForumTime(year, month, day, hours, minutes)); - } + } } ); @@ -3154,6 +3228,8 @@ function updateScriptSettings(theForm) var result = {}; $(theForm).find("input,textarea").each(function() { + if (this.type == "radio" && !this.checked) return; + if (this.type == "checkbox") { result[this.name] = this.checked ? 1 : 0; @@ -3194,7 +3270,7 @@ function addScriptSettings() div.append(''); settings.forEach(function(id) { - var v = options[id[0]], name = id[0], t = id[1], desc = id[2]; + var v = options[id[0]], name = id[0], t = id[1], desc = id[2], opt = id[3]; var c = $('
'); if (t == "boolean") { @@ -3209,6 +3285,22 @@ function addScriptSettings() { c.append('' + desc + ':'); } + else if (t == "radio") + { + c.append('' + desc + ':'); + for (var key in opt) if (opt.hasOwnProperty(key)) + { + var id = "anbt_" + name + "_" + key; + $('') + .attr({id: id, name: name, value: key, "data-subtype": ($.isArray(opt) ? "number" : "string")}) + .prop("checked", key == v) + .appendTo(c); + $('