Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Unpixel Tool
- // @version 1.0.2
- // @description Tool for replacing some pixels.
- // @authors dimden
- // @match *.ourworldofpixels.com/*
- // @match augustberchelmann.com/owop/*
- // @match https://owoppa.netlify.com/*
- // @match https://owoppa.000webhostapp.com/*
- // @grant none
- // ==/UserScript==
- // 90% shit, 10% tool!
- // Sometimes I need to fill only one colour, so I made this poopy tool for this.
- // You select colour that you only need to change, and just draw! It will replace only colour that you need.
- // by dimden | fluffyboi#1877
- // How it works: http://recordit.co/r2OcNYeYCW
- // 1.0.1 - You can now Reverse tool! It will replace all colours but not colour that you need.
- // 1.0.2 - Now you can use it in Console and TamperMonkey, and it will work everywhere.
- var UnpixelTool = function () {
- OWOP.tool.addToolObject(new OWOP.tool.class('Unpixel', OWOP.cursors.cursor, OWOP.fx.player.RECT_SELECT_ALIGNED(1), false, function(tool){
- function hex2rgb(hex) {
- return ['0x' + hex[1] + hex[2] | 0, '0x' + hex[3] + hex[4] | 0, '0x' + hex[5] + hex[6] | 0];
- };
- document.getElementById("palette-bg").insertAdjacentHTML('afterEnd',
- `
- <input id="unpixel-check" style="position: absolute;left:42px;top: 370px;background-color: rgba(231,24,24,0.5);border-style: outset;font-size: 15px; z-index: 999" type="checkbox"></input>
- `);
- function componentToHex(c) {
- var hex = c.toString(16);
- return hex.length == 1 ? "0" + hex : hex;
- }
- function rgb2hex(r, g, b) {
- return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
- };
- function arraysEqual(a, b) {
- if (a === b) return true;
- if (a == null || b == null) return false;
- if (a.length != b.length) return false;
- for (var i = 0; i < a.length; ++i) {
- if (a[i] !== b[i]) return false;
- }
- return true;
- }
- tool.setEvent("select", function() {
- document.getElementById("tool-unpixel").innerHTML = `
- <input type="color" id="unpixel-input"></input>`;
- document.getElementById("unpixel-input").value = rgb2hex(OWOP.player.selectedColor[0],OWOP.player.selectedColor[1],OWOP.player.selectedColor[2]);
- document.getElementById("unpixel-input").addEventListener("change", function () {
- unpixel_color = hex2rgb(document.getElementById("unpixel-input").value);
- }, false);
- unpixel_color = hex2rgb(document.getElementById("unpixel-input").value);
- });
- tool.setEvent("deselect", function() {
- document.getElementById("tool-unpixel").innerHTML = `<div style="background-image: url("http://ourworldofpixels.com/img/toolset.png"); background-position: 0px 0px;"></div>`;
- });
- tool.setEvent("mousemove mousedown", function(mouse, event) {if(mouse.buttons != 0){if(!document.getElementById("unpixel-check").checked){if(arraysEqual(OWOP.world.getPixel(OWOP.mouse.tileX,OWOP.mouse.tileY),unpixel_color)) {OWOP.world.setPixel(OWOP.world.setPixel(OWOP.mouse.tileX,OWOP.mouse.tileY,OWOP.player.selectedColor,1))}}else{if(!arraysEqual(OWOP.world.getPixel(OWOP.mouse.tileX,OWOP.mouse.tileY),unpixel_color)) {OWOP.world.setPixel(OWOP.world.setPixel(OWOP.mouse.tileX,OWOP.mouse.tileY,OWOP.player.selectedColor,1))}};}});
- }));
- };
- navData = window.performance.getEntriesByType("navigation");
- if (navData.length > 0 && navData[0].loadEventEnd > 0)
- {
- UnpixelTool();
- } else {
- window.addEventListener('load', function() {
- setTimeout(UnpixelTool, 1234);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment