您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Helps turn polygon markers on Kanka maps into lines to represent paths.
当前为
- // ==UserScript==
- // @name Kanka Map Path Helper
- // @namespace http://tampermonkey.net/
- // @license MIT
- // @version 2
- // @description Helps turn polygon markers on Kanka maps into lines to represent paths.
- // @author Salvatos
- // @match https://kanka.io/*/campaign/*/maps/*/map_markers*
- // @icon https://www.google.com/s2/favicons?domain=kanka.io
- // @run-at document-end
- // ==/UserScript==
- // Locate form field
- const coordbox = document.querySelector('#marker-poly textarea[name="custom_shape"]');
- // Create button
- var pathMakerInfo = `<label style="margin-top: 10px;">Path Helper<sup> beta</sup></label><p style="color: var(--text-help); margin-bottom: 5px;">Use the button below to turn your coordinates into a continuous line, for example to represent roads or itineraries. Duplicate points will be omitted, which may cause errors if your path visits the same (exact) point multiple times. To prolong an existing path, simply click the new coordinates, activate the button and those points will be added from the previous end of the path. Remember to set your stroke options to make it visible.</p>`;
- var pathMakerBtn = `
- <button type="button" id="path-helper" class="note-btn btn btn-default" title="Make into path">
- Make into path
- </button>`;
- coordbox.insertAdjacentHTML("afterend", pathMakerBtn);
- coordbox.insertAdjacentHTML("afterend", pathMakerInfo);
- // Add click event to button
- document.getElementById('path-helper').addEventListener('click', function () {
- // Extract all coordinates from input into array
- var coords1 = coordbox.value.trim().split(" ");
- // Remove duplicates (for successive button clicks, prolonging existing paths, etc.)
- var coords2 = uniq(coords1);
- function uniq(a) {
- return Array.from(new Set(a));
- }
- // Start a fresh array with the unique coords in the initial order, then reverse our copy
- let coords = [].concat(coords2);
- coords2.reverse();
- // Iterate through coords backwards and append them
- coords2.forEach(function (item) {
- if (item != coords2[0]) { // Omit extremity
- coords.push(item);
- }
- });
- // Push new coords to textarea
- coordbox.value = coords.join (" ");
- });