{"size": 1193, "ext": "js", "max_stars_repo_path": "resources/Content/tweetdeck/add_tweetduck_to_settings_menu.js", "max_stars_repo_name": "chylex/TweetDick", "max_stars_repo_stars_event_min_datetime": "2016-04-10T10:32:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-15T16:17:48.000Z", "max_issues_repo_path": "resources/Content/tweetdeck/add_tweetduck_to_settings_menu.js", "max_issues_repo_name": "chylex/TweetDick", "max_issues_repo_issues_event_min_datetime": "2016-04-11T22:10:22.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-16T10:24:02.000Z", "max_forks_repo_path": "resources/Content/tweetdeck/add_tweetduck_to_settings_menu.js", "max_forks_repo_name": "chylex/TweetDick", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 29.0975609756, "max_line_length": 138, "alphanum_fraction": 0.6856663873}
import { $TD } from "../api/bridge.js";
import { onAppReady } from "../api/ready.js";

/**
 * @param {HTMLUListElement} list
 */
function addMenuItems(list) {
	const allDividers = list.querySelectorAll(":scope > li.drp-h-divider");
	const lastDivider = allDividers[allDividers.length - 1];
	
	lastDivider.insertAdjacentHTML("beforebegin", "<li class=\"is-selectable\" data-tweetduck><a href=\"#\" data-action>TweetDuck</a></li>");
	
	const button = list.querySelector("[data-tweetduck]");
	
	button.querySelector("a").addEventListener("click", function() {
		$TD.openContextMenu();
	});
	
	button.addEventListener("mouseenter", function() {
		button.classList.add("is-selected");
	});
	
	button.addEventListener("mouseleave", function() {
		button.classList.remove("is-selected");
	});
}

/**
 * Adds a 'TweetDuck' menu item to the left-side Settings menu.
 */
export default function() {
	onAppReady(function setupSettingsMenu() {
		document.querySelector("[data-action='settings-menu']").addEventListener("click", () => setTimeout(function() {
			const list = document.querySelector("nav.app-navigator .js-dropdown-content ul");
			if (list) {
				addMenuItems(list);
			}
		}, 0));
	});
};
