// ==UserScript==
// @author      PotcFdk
// @name        Archive.org AutoSaver
// @namespace   https://github.com/PotcFdk/ArchiveOrgAutoSaver
// @description Auto-saves all missing pages that you might encounter.
// @include     https://web.archive.org/web/*
// @include     https://web.archive.org/save/*
// @version     0.0.8
// @grant       none
// @downloadURL https://raw.githubusercontent.com/PotcFdk/ArchiveOrgAutoSaver/master/Archive.org_AutoSaver.user.js
// @updateURL   https://raw.githubusercontent.com/PotcFdk/ArchiveOrgAutoSaver/master/Archive.org_AutoSaver.meta.js
// ==/UserScript==

/*
	Archive.org AutoSaver - Copyright (c) PotcFdk, 2015

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

var livewebInfo = document.getElementById('livewebInfo');
if (livewebInfo) {
	var saveLink = livewebInfo.getElementsByTagName ("a");
	if (saveLink && saveLink[0] && saveLink[0].textContent
		&& saveLink[0].textContent == "Save this url in the Wayback Machine")
	{
		console.log ("[Archive.org AutoSaver] Detected missing page. Redirecting...");
		window.location.href = saveLink[0].href;
	}
}

var error = document.getElementById ('error');
var form1 = document.getElementsByName ('form1');
if (error && error.textContent
	&& (error.textContent.indexOf ('Wayback Machine doesn\'t have that page archived.') != -1
		|| error.textContent.indexOf ('This url is not available on the live web or can not be archived.') != -1)
	&& form1 && form1[0])
{
	var reqUrlInput = form1[0].getElementsByTagName ('input');
	if (reqUrlInput && reqUrlInput[0] && reqUrlInput[0].value)
	{
		error.innerHTML = error.innerHTML
			+ '<p>[Archive.Org AutoSaver] <a href="//web.archive.org/save/'
			+ reqUrlInput[0].value
			+ '">Click here</a> to try to save this url anyways.</p>';
		console.log ("[Archive.org AutoSaver] Detected not available page. Added save link.");
	}
}

var recordDoneClose = document.getElementById ('__wb_record_done_close')
if (recordDoneClose && __on_wb_record_done_close) {
	__on_wb_record_done_close();
	console.log ("[Archive.org AutoSaver] Closed 'Page saved as' window.");
}

if ((typeof go != 'undefined') && {}.toString.call (go) == '[object Function]') {
	console.log ("[Archive.org AutoSaver] Speeding up redirect...");
	window.setTimeout (go, 500);
}

@@ -1185,16 +1185,472 @@
 se.%0A*/%0A%0A
+function setExtendedMode (onoff)%0A%7B%0A%09if (onoff) %7B%0A%09%09localStorage.setItem ('AOAS_ExtendedMode', true);%0A%09%09console.log ('%5BArchive.org AutoSaver%5D Enabled extended mode for this session.');%0A%09%7D else %7B%0A%09%09localStorage.setItem ('AOAS_ExtendedMode', false);%0A%09%09console.log ('%5BArchive.org AutoSaver%5D Disabled extended mode for this session.');%0A%09%7D%0A%7D%0A%0Afunction isExtendedModeEnabled ()%0A%7B%0A%09return !!JSON.parse (localStorage.getItem ('AOAS_ExtendedMode'));%0A%7D%0A%0A// Handlers%0A%0A
 var live
@@ -2510,16 +2510,252 @@
 lue)%0A%09%7B%0A
+%09%09if (isExtendedModeEnabled ()) %7B%0A%09%09%09console.log (%22%5BArchive.org AutoSaver%5D Detected not available page. Extended mode is enabled, redirecting...%22);%0A%09%09%09window.location.href = '//web.archive.org/save/' + reqUrlInput%5B0%5D.value;%0A%09%09%7D else %7B%0A%09
 %09%09error.
@@ -2782,16 +2782,17 @@
 nerHTML%0A
+%09
 %09%09%09+ '%3Cp
@@ -2853,16 +2853,17 @@
 ve/'%0A%09%09%09
+%09
 + reqUrl
@@ -2877,16 +2877,17 @@
 %5D.value%0A
+%09
 %09%09%09+ '%22%3E
@@ -2938,24 +2938,25 @@
 ys.%3C/p%3E';%0A%09%09
+%09
 console.log 
@@ -3030,16 +3030,20 @@
 ink.%22);%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A%0Ava

Add an 'extended mode' that will auto-save unavailable pages, too.