// IP.Board: New Topic Confirm
// Copyright (c) 2006-2007 Orbona
// Version 1.0
// Release Date: 2007-10-22
//
// See also: http://www.orbona.com/greasemonkey/
//
// Original file name: ipboard_newtopicconfirm.user.js
// Please reference the original file name when contacting me regarding this
// script.
//
// This software is licensed under the CC-GNU GPL:
// http://creativecommons.org/license/cc-gpl
//
//---------------------------------------------------------------------------
// DESCRIPTION
//
// This script adds an "Are you sure" prompt to the "Add New Topic" button on
// an Invision Power Board (IP.Board, see http://www.invisionpower.com).
// Currently, I only use this script on the Television Without Pity forums
// since they have strict rules about posting new topics. On the TWoP forums
// I'm fairly certain I'll never want to create a new topic. The
// confirmation alert helps to prevent new-topic accidents.
// --------------------------------------------------------------------------

// ==UserScript==
// @name            IP.Board: New Topic Confirm
// @description     Adds a confirmation prompt to the Add New Topic buttons
// @namespace       http://www.orbona.com/greasemonkey/
// @include         http://forums.televisionwithoutpity.com/index.php?show*
// ==/UserScript==

function confirmNewTopic(event) {
   var ans= confirm("Are you sure you want to start a new topic? Click OK to continue with your new topic, or Cancel to cancel this action (and avoid making a fool of yourself).");
   if (!ans) {
      event.stopPropagation();
      event.preventDefault();
   }
   return (ans);
}

function doIt() {
   var links=document.evaluate("//A[contains(@href,'new_post')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,  null);

   for (var i = 0; i < links.snapshotLength; i++)
      links.snapshotItem(i).addEventListener('click', confirmNewTopic, true);
}

window.addEventListener("load", function() { doIt(); }, false);
