0 Replies - 44 Views - Last Post: Today, 08:51 AM

#1 searchtheskyes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • Posts: 1
  • Joined: Today, 08:39 AM

chrome extension update to manifest 2 issue

Posted Today, 08:51 AM

Hi, I'm trying to update an outdated chrome extension (I'm not a coder, just playing around to learn). It needed to be updated from the manifest 1 version to manifest 2.

I've added "manifest_version": 2, <-as required by chrome
I've changed "background_page": "main.html"
to "background": {
"page": "main.html",
"persistent": true
},
and under permissions I have changed "unlimited_storage" to "unlimitedStorage"
all of these were required by chrome...
(none of these things have cause an issue when loading the unpacked extension)

BUT, the extension no longer works.. It goes to the options page, and then the buttons won't bring up the secondary page as it did before. I'm assuming there are more updates I need to make to the code, but don't know what?

What else do I need to change? I hope you can help me!


Manifest -->

{
"manifest_version": 2,
	"name": "WatchAds",
	"version": "2.2",
	"description": "Ad Watcher.",
	"icons": {
		"48": "adaware.png",
		"128": "adaware.png"
	},
	
	"background": {
		"page": "main.html",
		"persistent": true
	},
	"options_page": "main.html",
	"permissions": [
		"tabs",
		"unlimitedStorage",
		"history"
	]
}


main.js -->

/* 
  @collection
  Sorry for my bad Javascript ^_^/>/>/>
*/
m = {
	key: 'history', //key for local storage
	ls: window.localStorage, //local alias
	
	/* Clear stored data */
	clearData: function() {
		m.ls.removeItem( m.key );
		m.ls.setItem( m.key, "[]" ); //initialize our var' as JSON's array
	},
	
	/* Get stored data helper */
	get: function() {
		if ( m.ls.getItem( m.key ) == null ) { //var' isn't initialized
			m.ls.setItem( m.key, "[]" );
		}
	
		/* Local storage provides only string saving. Using JSON for [un]serializing arrays */
		return JSON.parse( m.ls.getItem( m.key ) );
	},
	
	/* Set stored data helper */
	set: function( v ) {
		m.ls.setItem( 
			m.key, 
			JSON.stringify( (m.get()).concat( [v] ) ) //concat prev' and present data, JSON it
		);
	},
	
	/* Callback for event listener */
	callbackTabs: function( id, i, tab ) {
		if ( tab.status == 'complete' ) { //event fires 2 times: "loading" and "complete" states
			m.set( { //store that
				date: m.date(),
				favIcon: tab.favIconUrl || '',
				url: tab.url || '',
				title: tab.title || '',
				incognito: tab.incognito
			} );
		}
	},

	/* Ugly date format helper */
	date: function() {
		d = new Date();
		return '' + (
			( d.getDate() > 9 ? d.getDate() : '0' + d.getDate() ) + ' ' + 
				['January','February','March','April','May','June','July','August',
					'September','October','November','December'][d.getMonth()] +
				' ' + d.getFullYear() + ', ' + 
				( d.getHours() > 9 ? d.getHours() : '0' + d.getHours() ) + ':' + 
				( d.getMinutes() > 9 ? d.getMinutes() : '0' + d.getMinutes() ) + ':' +
				( d.getSeconds() > 9 ? d.getSeconds() : '0' + d.getSeconds() )
		);
	},
	
	/* $(id) getter */
	$: function( id ) {
		return document.getElementById( id );
	},
	
	/* Helper for decomposition of an URL */
	parseURL: function( url ) {
		var a =  document.createElement('a');
		a.href = url;
		
		//some extra parts are commented, we don't need 'em
		return { 
			/* source: url,
			protocol: a.protocol.replace(':',''), */
			host: a.hostname,
			/* port: a.port,
			query: a.search,
			params: (function(){
				var ret = {},
					seg = a.search.replace(/^\?/,'').split('&'),
					len = seg.length, i = 0, s;
				for (;i<len;i++) {
					if (!seg[i]) { continue; }
					s = seg[i].split('=');
					ret[s[0]] = s[1];
				}
				return ret;
			})(),
			file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
			hash: a.hash.replace('#',''), */
			path: a.pathname.replace(/^([^\/])/,'/$1')/* ,
			relative: (a.href.match(/tp:\/\/[^\/]+(.+)/) || [,''])[1],
			segments: a.pathname.replace(/^\//,'').split('/') */
		};
	},
	
	/* Displaying history helper. History iterator */
	displayData: function() {
		var html = ''; //dirty working with DOM
		
		(m.get()).forEach( function( v ) {
			p = m.parseURL( v.url );
			
			html += '<li><span>' + v.date + '</span> ' + ( v.incognito ? '<strong>incognito mode</strong> ' : '') 
				+ '<a href="' + v.url + '"><img src="' 
					+ ( v.favIcon ? v.favIcon : ('http://www.google.com/s2/favicons?domain=' + p.host) ) + '"/>' 
				+ ( v.title ? v.title : ((p.host + p.path ).substr( 0, 80 )) ) + '</a></li>';
		});
		
		m.$( 'putHere' ).innerHTML = html;
		
		return false;
	}
};

/* Add a tabs listener */
chrome.tabs.onUpdated.addListener( m.callbackTabs );



main.html -->

<script type="text/javascript" src="main.js"></script>
<style type="text/css">
	#putHere {
		list-style-type: none;
	}
		span {
			color: #ddd;
				-webkit-transition: 1s;
		}
			span:hover {
				color: #000;
			}
		
		#putHere a, strong {
			margin-left: 20px;
			text-decoration: none;
		}
		
		img {
			margin-right: 7px;
			position: relative;
			top: 3px;
			width: 16px;
			height: 16px;
		}
</style>
<ul>
	<li><a href="javascript:m.displayData()">Show</a></li>
	<li><a href="javascript:( m.clearData() || m.displayData() )">Clear</a></li>
</ul>
<ul id="putHere"></ul>

:code:

This post has been edited by modi123_1: Today, 09:20 AM
Reason for edit:: please use the 'code' tag button in the editor


Is This A Good Question/Topic? 0
  • +

Page 1 of 1