'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var isUdf = _interopDefault(require('./isUdf'));

/**
 * 把页面加入浏览器收藏夹
 * @param {string} url
 * @param {string} title
 * @returns
 */
function setToFavorite(url, title) {
  if (isUdf(url)) url = window.location.href;
  if (isUdf(title)) title = document.title;

  try {
    window.external.addFavorite(url, title);
  } catch (err) {
    try {
      window.sidebar.addPanel(title, url, '');
    } catch (e) {
      console.error('加入收藏失败，请使用Ctrl+D进行添加');
      return null;
    }
  }
}

module.exports = setToFavorite;
