Extract Surnames

Extract Surnames from website

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Extract Surnames
// @name:en        Extract Surnames ds
// @description Extract Surnames from website
// @description:en Extract Surnames from websitedd sd
// @include     http://indiachildnames.com/surname/*
// @author      atul
// @version     1.0.7
// @grant       none
// @namespace   https://greasyfork.org/en/users/100769-atul-k
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// ==/UserScript==
(function () {
  var lNames = "";
  var Names = $("#contentstable :first").children();
  var storedValue = localStorage.getItem('clodura');
  if (!storedValue) {
      storedValue = 'surname,lanaguages,origin\n';
      localStorage.setItem('clodura', storedValue);
  }
  
  for(var i=1; i < Names.length; i++) {
  	var surname = $(Names[i]).children('td :first').text();
    var language = $(Names[i]).children('td :nth-child(2)').text();
    language = language.split(',').join(';');
    var origin = $(Names[i]).children('td :last').text();
    origin = origin.split(',').join(';');
    var final = surname + "," + language + "," + origin;
    lNames = lNames + final + '\n';
  }
  
  storedValue = storedValue + lNames;  
  localStorage.setItem('clodura', storedValue);
  
  var a = $('table#clienttable > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(5) > td > table > tbody >tr > td:last').children('font:last ~ a')[0];
  
  if(a) {
      var href = a.href;
      href = href.split('http://indiachildnames.com/surname/')[1];
      window.location.replace(href);
  } 
  else {
      var c = $('table#clienttable > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(5) > td > table > tbody >tr > td:last').children('font:first ~ a:first')[0];
    
      if(c) {
          var href2 = c.href;
          href2 = href2.split('http://indiachildnames.com/surname/')[1];
          window.location.replace(href2);
      }
      else {
        // Start file download.
        download("surnames.csv",localStorage.getItem('clodura'));          
      }
  }

    function download(filename, text) {
      var element = document.createElement('a');
      element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
      element.setAttribute('download', filename);
    
      element.style.display = 'none';
      document.body.appendChild(element);
    
      element.click();
    
      document.body.removeChild(element);
    }
  
}) ();