IMDB List Importer

Import list of titles, people or characters in the imdb list

目前为 2016-10-26 提交的版本。查看 最新版本

// ==UserScript==
// @name        IMDB List Importer
// @namespace   Neinei0k_imdb
// @include     http://www.imdb.com/list/edit*
// @version     3.2
// @grant       none
// @description Import list of titles, people or characters in the imdb list
// ==/UserScript==

unsafeWindow.create_list = function() {
  var re
  if (document.getElementsByClassName('list_characters').length != 0) {
    re = /ch[0-9]{7}/
  } else if (document.getElementsByClassName('list_people').length != 0) {
    re = /nm[0-9]{7}/
  } else if (document.getElementsByClassName('list_titles').length != 0) {
    re = /tt[0-9]{7}/
  } else {
    return []
  }
    
  var text = document.getElementById('Neinei0k-imdb-list-importer').children[0].value
  var list = []
  var e
  while ((e = re.exec(text)) != null) {
    var rer = new RegExp(e[0], 'g')
    text = text.replace(rer, '')
    list.push(e[0])
  }
  
  return list
}

unsafeWindow.add_list = function(list) {
  var length = list.length
  var list_id = /ls[0-9]{1,}/.exec(location.href)[0]
  
  var ready_e = document.getElementById('Neinei0k-imdb-list-importer').children[1]
  var ready = 0
  function showReady() {
    if (this.readyState == 4 && this.status == 200) {
      ready += 1
      ready_e.innerHTML = "Ready "+ready+" of "+length+"."
      if (ready == length)
        ready_e.innerHTML += " Reload the page."
    }
  }
  
  for (var i = 0; i < length; i++) {
    var xhttp = new XMLHttpRequest()
    console.log('Add element '+(i+1)+': '+list[i])
    xhttp.onreadystatechange = showReady
    xhttp.open('POST', '/list/_ajax/edit', true)
    xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
    xhttp.send("const="+list[i]+"&list_id="+list_id)
  }
}

var field = document.createElement('textarea')
field.style.backgroundColor = 'white'

var readyText = document.createElement('div')
readyText.innerHTML = "Insert text with id's in the field above and press button 'Import list'"

var button = document.createElement('button')
button.setAttribute('class', 'btn')
button.setAttribute('onclick', 'add_list(create_list())')
button.textContent = 'Import list'

var div = document.createElement('div')
div.setAttribute('id','Neinei0k-imdb-list-importer')
div.setAttribute('class', 'add')
div.appendChild(field)
div.appendChild(readyText)
div.appendChild(button)

var list_edit = document.querySelector('.list_edit')
var footer = document.querySelector('.footer')
list_edit.insertBefore(div, footer)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址